-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Phillip Rak <[email protected]>
- Loading branch information
1 parent
1693709
commit 3fb53be
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { stripOrigin } from '../url'; | ||
|
||
describe('stripOrigin', () => { | ||
// eslint-disable-next-line jest/no-hooks | ||
beforeAll(() => { | ||
process.env.BASE_URL = 'https://example.com'; | ||
}); | ||
|
||
// eslint-disable-next-line jest/no-hooks | ||
afterAll(() => { | ||
delete process.env.BASE_URL; | ||
}); | ||
|
||
it('should strip origin from a valid absolute URL', () => { | ||
const url = 'https://example.com/path/to/resource?query=value'; | ||
|
||
expect(stripOrigin(url)).toBe('/path/to/resource?query=value'); | ||
}); | ||
|
||
it('should strip origin from a valid relative URL', () => { | ||
const url = '/path/to/resource?query=value'; | ||
|
||
expect(stripOrigin(url)).toBe('/path/to/resource?query=value'); | ||
}); | ||
|
||
it('should return the original URL if it is invalid', () => { | ||
const url = 'invalid-url'; | ||
|
||
expect(stripOrigin(url, '')).toBe('invalid-url'); | ||
}); | ||
|
||
it('should handle URLs without search queries', () => { | ||
const url = 'https://example.com/path/to/resource'; | ||
|
||
expect(stripOrigin(url)).toBe('/path/to/resource'); | ||
}); | ||
|
||
it('should handle URLs with only search queries', () => { | ||
const url = 'https://example.com?query=value'; | ||
|
||
expect(stripOrigin(url)).toBe('/?query=value'); | ||
}); | ||
|
||
it('should handle URLs with only path', () => { | ||
const url = 'https://example.com/path/to/resource'; | ||
|
||
expect(stripOrigin(url)).toBe('/path/to/resource'); | ||
}); | ||
|
||
it('should handle URLs with only search query in relative URL', () => { | ||
const url = '?query=value'; | ||
|
||
expect(stripOrigin(url)).toBe('/?query=value'); | ||
}); | ||
|
||
it('should handle URLs with only path in relative URL', () => { | ||
const url = '/path/to/resource'; | ||
|
||
expect(stripOrigin(url)).toBe('/path/to/resource'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters