utils.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { isUrl } from './utils';
  2. describe('isUrl tests', (): void => {
  3. it('should return false for invalid and corner case inputs', (): void => {
  4. expect(isUrl([] as any)).toBeFalsy();
  5. expect(isUrl({} as any)).toBeFalsy();
  6. expect(isUrl(false as any)).toBeFalsy();
  7. expect(isUrl(true as any)).toBeFalsy();
  8. expect(isUrl(NaN as any)).toBeFalsy();
  9. expect(isUrl(null as any)).toBeFalsy();
  10. expect(isUrl(undefined as any)).toBeFalsy();
  11. expect(isUrl('')).toBeFalsy();
  12. });
  13. it('should return false for invalid URLs', (): void => {
  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', (): void => {
  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. });