-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
location
stub utility (#28)
* feat: Add `location` stub from prerenderer as a utility * fix: Setup `globalThis.location` & support class methods * test: Add tests for locationStub utility
- Loading branch information
1 parent
6cfff8b
commit 1337db0
Showing
3 changed files
with
55 additions
and
0 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
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
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,36 @@ | ||
import { describe, it, beforeEach, expect } from '@jest/globals'; | ||
import { locationStub } from '../src/prerender.js'; | ||
|
||
describe('location-stub', () => { | ||
beforeEach(() => { | ||
if (globalThis.location) { | ||
delete globalThis.location; | ||
} | ||
}); | ||
|
||
it('Contains all Location instance properties', () => { | ||
locationStub('/foo/bar?baz=qux#quux'); | ||
|
||
[ | ||
// 'ancestorOrigins', // Not supported by FireFox and sees little use, but we could add an empty val if it's needed | ||
'hash', | ||
'host', | ||
'hostname', | ||
'href', | ||
'origin', | ||
'pathname', | ||
'port', | ||
'protocol', | ||
'search', | ||
].forEach(key => { | ||
expect(globalThis.location).toHaveProperty(key); | ||
}); | ||
}); | ||
|
||
// Do we need to support `assign`, `reload`, and/or `replace`? | ||
it('Support bound methods', () => { | ||
locationStub('/foo/bar?baz=qux#quux'); | ||
|
||
expect(globalThis.location.toString()).toBe('http://localhost/foo/bar?baz=qux#quux'); | ||
}); | ||
}); |