Skip to content

Commit cd24594

Browse files
fix: support native URLSearchParams (#15)
1 parent 31c8fcc commit cd24594

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This project "fixes" the following global APIs, overriding whichever polyfills t
3636
- `TextDecoderStream`
3737
- `structuredClone()`
3838
- `URL`
39+
- `URLSearchParams`
3940

4041
## Getting started
4142

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class FixedJSDOMEnvironment extends JSDOMEnvironment {
1818
this.global.fetch = fetch
1919
this.global.structuredClone = structuredClone
2020
this.global.URL = URL
21+
this.global.URLSearchParams = URLSearchParams
2122
}
2223
}
2324

index.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ test('exposes "URL"', () => {
132132
expect(globalThis).toHaveProperty('URL')
133133
expect(new URL('http://localhost')).toBeInstanceOf(BuiltinURL)
134134
})
135+
136+
test('exposes "URLSearchParams" and makes it mockable', () => {
137+
jest
138+
.spyOn(URLSearchParams.prototype, 'has')
139+
.mockImplementation((key) => key === 'mocked_flag')
140+
141+
expect(globalThis).toHaveProperty('URLSearchParams')
142+
expect(new URL('http://localhost?other_non_mocked_flag').searchParams.has('other_non_mocked_flag')).toBe(false)
143+
expect(new URL('http://localhost?other_non_mocked_flag').searchParams.has('mocked_flag')).toBe(true)
144+
})

0 commit comments

Comments
 (0)