|
12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import * as fc from 'fast-check'
- import getUrlScheme, { UrlScheme } from './getUrlScheme'
-
- it('should exist', () => {
- expect(getUrlScheme).toBeDefined()
- })
-
- it('should be a callable', () => {
- expect(typeof getUrlScheme).toBe('function')
- })
-
- it('should accept 1 argument', () => {
- expect(getUrlScheme).toHaveLength(1)
- })
-
- test.each`
- scheme | kind
- ${'http'} | ${'HTTP'}
- ${'https'} | ${'HTTPS'}
- `('should detect $kind URLs', ({ scheme, kind }) => {
- fc.assert(
- fc.property(fc.webUrl({ validSchemes: [scheme] }), url => {
- expect(getUrlScheme(url)).toBe(UrlScheme[kind as keyof typeof UrlScheme])
- })
- )
- })
-
- it('should fall back to local URLs', () => {
- fc.assert(
- fc.property(
- fc.array(
- fc.oneof(
- fc.string().filter(s => /^[a-zA-Z0-9._-]+$/.test(s)),
- fc.constant('..'),
- fc.constant('.')
- )
- ),
- pathFragments => {
- expect(getUrlScheme(pathFragments.join('/'))).toBe(UrlScheme.FILE)
- }
- )
- )
- })
|