isPossiblePhoneNumber.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var _isPossiblePhoneNumber2 = _interopRequireDefault(require("./isPossiblePhoneNumber.js"));
  3. var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
  4. var _metadataMin2 = _interopRequireDefault(require("../test/metadata/1.0.0/metadata.min.json"));
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  6. function isPossiblePhoneNumber() {
  7. for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
  8. parameters[_key] = arguments[_key];
  9. }
  10. parameters.push(_metadataMin["default"]);
  11. return _isPossiblePhoneNumber2["default"].apply(this, parameters);
  12. }
  13. describe('isPossiblePhoneNumber', function () {
  14. it('should detect whether a phone number is possible', function () {
  15. isPossiblePhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true);
  16. isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false);
  17. isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false);
  18. isPossiblePhoneNumber('8 (800) 555 35 35', {
  19. defaultCountry: 'RU'
  20. }).should.equal(true);
  21. isPossiblePhoneNumber('+7 (800) 555 35 35').should.equal(true);
  22. isPossiblePhoneNumber('+7 1 (800) 555 35 35').should.equal(false);
  23. isPossiblePhoneNumber(' +7 (800) 555 35 35').should.equal(false);
  24. isPossiblePhoneNumber(' ').should.equal(false);
  25. });
  26. it('should detect whether a phone number is possible when using old metadata', function () {
  27. expect(function () {
  28. return (0, _isPossiblePhoneNumber2["default"])('8 (800) 555 35 35', 'RU', _metadataMin2["default"]);
  29. }).to["throw"]('Missing "possibleLengths" in metadata.');
  30. (0, _isPossiblePhoneNumber2["default"])('+888 123 456 78901', _metadataMin2["default"]).should.equal(true);
  31. });
  32. });
  33. //# sourceMappingURL=isPossiblePhoneNumber.test.js.map