Skip to content

Commit

Permalink
Add test for when addParams is called with an existing key
Browse files Browse the repository at this point in the history
  • Loading branch information
mutuajames committed Jun 27, 2023
1 parent 2f0b604 commit 634a21b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react-utils/src/hooks/tests/useSearchParams.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ test('useSimpleSearch works correctly', () => {
current.addParam('key2', 'value2');
expect(current.sParams.toString()).toEqual('key=value&key1=value1&key2=value2');

//Test that when we call addParams to an existing key we replace it instead of appending
current.addParam('key1', 'newValue3');
expect(current.sParams.toString()).toEqual('key=value&key1=newValue3&key2=value2');

expect(history.location).toMatchObject({
hash: '',
key: expect.any(String),
pathname: '/qr',
search: '?key=value?key=value&key1=value1?key=value&key1=value1&key2=value2',
search:
'?key=value?key=value&key1=value1?key=value&key1=value1&key2=value2?key=value&key1=newValue3&key2=value2',
state: undefined,
});

Expand All @@ -46,7 +51,7 @@ test('useSimpleSearch works correctly', () => {
key: expect.any(String),
pathname: '/qr',
search:
'?key=value?key=value&key1=value1?key=value&key1=value1&key2=value2?key=value&key2=value2',
'?key=value?key=value&key1=value1?key=value&key1=value1&key2=value2?key=value&key1=newValue3&key2=value2?key=value&key2=value2',
state: undefined,
});
});

0 comments on commit 634a21b

Please sign in to comment.