utils.test.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { isUrl } from './utils';
  2. describe('isUrl tests', () => {
  3. it('should return false for invalid and corner case inputs', () => {
  4. expect(isUrl([])).toBeFalsy();
  5. expect(isUrl({})).toBeFalsy();
  6. expect(isUrl(false)).toBeFalsy();
  7. expect(isUrl(true)).toBeFalsy();
  8. expect(isUrl(NaN)).toBeFalsy();
  9. expect(isUrl(null)).toBeFalsy();
  10. expect(isUrl(undefined)).toBeFalsy();
  11. expect(isUrl('')).toBeFalsy();
  12. });
  13. it('should return false for invalid URLs', () => {
  14. expect(isUrl('foo')).toBeFalsy();
  15. expect(isUrl('bar')).toBeFalsy();
  16. expect(isUrl('bar/test')).toBeFalsy();
  17. expect(isUrl('http:/example.com/')).toBeFalsy();
  18. expect(isUrl('ttp://example.com/')).toBeFalsy();
  19. });
  20. it('should return true for valid URLs', () => {
  21. expect(isUrl('http://example.com/')).toBeTruthy();
  22. expect(isUrl('https://example.com/')).toBeTruthy();
  23. expect(isUrl('http://example.com/test/123')).toBeTruthy();
  24. expect(isUrl('https://example.com/test/123')).toBeTruthy();
  25. expect(isUrl('http://example.com/test/123?foo=bar')).toBeTruthy();
  26. expect(isUrl('https://example.com/test/123?foo=bar')).toBeTruthy();
  27. expect(isUrl('http://www.example.com/')).toBeTruthy();
  28. expect(isUrl('https://www.example.com/')).toBeTruthy();
  29. expect(isUrl('http://www.example.com/test/123')).toBeTruthy();
  30. expect(isUrl('https://www.example.com/test/123')).toBeTruthy();
  31. expect(isUrl('http://www.example.com/test/123?foo=bar')).toBeTruthy();
  32. expect(isUrl('https://www.example.com/test/123?foo=bar')).toBeTruthy();
  33. });
  34. });