Sha256: 82a3447b4e5c7cf32cc8492086ae2179976968cc4ce3ed4b8d5c1b8814221f83
Contents?: true
Size: 1.74 KB
Versions: 26
Compression:
Stored size: 1.74 KB
Contents
/** * @vitest-environment jsdom */ import { normalizePath } from './normalizePath' test('returns RegExp as-is', () => { const path = /\/user\/(.+?)\// expect(normalizePath(path)).toEqual(path) }) test('returns a clean absolute URL as-is', () => { const path = 'https://test.mswjs.io/user' expect(normalizePath(path)).toEqual(path) }) test('rebases a relative URL against the current location', () => { const path = '/relative/url' expect(normalizePath(path)).toBe(`${location.origin}/relative/url`) }) test('rebases a relative URL against a custom base URL', () => { const path = '/relative/url' expect(normalizePath(path, 'https://test.mswjs.io')).toEqual( 'https://test.mswjs.io/relative/url', ) }) test('removes query parameters and hashes from an absolute URL', () => { const path = 'https://test.mswjs.io/user?query=123#some' expect(normalizePath(path)).toEqual('https://test.mswjs.io/user') }) test('removes query parameters and hashes from a relative URL', () => { expect(normalizePath('/user?query=123')).toEqual(`${location.origin}/user`) expect(normalizePath('/user#some')).toEqual(`${location.origin}/user`) expect(normalizePath('/user?query=123#some')).toEqual( `${location.origin}/user`, ) }) test('returns a path pattern string as-is', () => { expect(normalizePath(':api/user')).toEqual('http://localhost/:api/user') expect(normalizePath('*/resource/*')).toEqual('*/resource/*') }) test('removes query parameters and hashes from a path pattern string', () => { expect(normalizePath(':api/user?query=123#some')).toEqual( 'http://localhost/:api/user', ) }) test('preserves optional path parameters', () => { expect(normalizePath('/user/:userId?')).toEqual( 'http://localhost/user/:userId?', ) })
Version data entries
26 entries across 26 versions & 1 rubygems