isPossiblePhoneNumber.test.js 1.6 KB

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