isPossibleNumber.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import metadata from '../../metadata.min.json' assert { type: 'json' };
  2. import _isPossibleNumber from './isPossibleNumber.js';
  3. function isPossibleNumber() {
  4. for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
  5. parameters[_key] = arguments[_key];
  6. }
  7. parameters.push(metadata);
  8. return _isPossibleNumber.apply(this, parameters);
  9. }
  10. describe('isPossibleNumber', function () {
  11. it('should work', function () {
  12. isPossibleNumber('+79992223344').should.equal(true);
  13. isPossibleNumber({
  14. phone: '1112223344',
  15. country: 'RU'
  16. }).should.equal(true);
  17. isPossibleNumber({
  18. phone: '111222334',
  19. country: 'RU'
  20. }).should.equal(false);
  21. isPossibleNumber({
  22. phone: '11122233445',
  23. country: 'RU'
  24. }).should.equal(false);
  25. isPossibleNumber({
  26. phone: '1112223344',
  27. countryCallingCode: 7
  28. }).should.equal(true);
  29. });
  30. it('should work v2', function () {
  31. isPossibleNumber({
  32. nationalNumber: '111222334',
  33. countryCallingCode: 7
  34. }, {
  35. v2: true
  36. }).should.equal(false);
  37. isPossibleNumber({
  38. nationalNumber: '1112223344',
  39. countryCallingCode: 7
  40. }, {
  41. v2: true
  42. }).should.equal(true);
  43. isPossibleNumber({
  44. nationalNumber: '11122233445',
  45. countryCallingCode: 7
  46. }, {
  47. v2: true
  48. }).should.equal(false);
  49. });
  50. it('should work in edge cases', function () {
  51. // Invalid `PhoneNumber` argument.
  52. expect(function () {
  53. return isPossibleNumber({}, {
  54. v2: true
  55. });
  56. }).to["throw"]('Invalid phone number object passed'); // Empty input is passed.
  57. // This is just to support `isValidNumber({})`
  58. // for cases when `parseNumber()` returns `{}`.
  59. isPossibleNumber({}).should.equal(false);
  60. expect(function () {
  61. return isPossibleNumber({
  62. phone: '1112223344'
  63. });
  64. }).to["throw"]('Invalid phone number object passed'); // Incorrect country.
  65. expect(function () {
  66. return isPossibleNumber({
  67. phone: '1112223344',
  68. country: 'XX'
  69. });
  70. }).to["throw"]('Unknown country');
  71. });
  72. });
  73. //# sourceMappingURL=isPossibleNumber.test.js.map