-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(next-app-router): prevent client-side search when rerendering
- Loading branch information
Showing
2 changed files
with
41 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
37 changes: 37 additions & 0 deletions
37
packages/react-instantsearch-nextjs/src/__tests__/InstantSearchNext.test.tsx
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,37 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { createSearchClient } from '@instantsearch/mocks'; | ||
import { wait } from '@instantsearch/testutils'; | ||
import { act, render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { SearchBox } from 'react-instantsearch'; | ||
|
||
import { InstantSearchNext } from '../InstantSearchNext'; | ||
|
||
test('it rerenders without triggering a client-side search', async () => { | ||
const client = createSearchClient(); | ||
|
||
function Component() { | ||
return ( | ||
<InstantSearchNext searchClient={client} indexName="indexName"> | ||
<SearchBox /> | ||
</InstantSearchNext> | ||
); | ||
} | ||
|
||
const { rerender } = render(<Component />); | ||
|
||
await act(async () => { | ||
await wait(0); | ||
}); | ||
|
||
rerender(<Component />); | ||
|
||
await act(async () => { | ||
await wait(0); | ||
}); | ||
|
||
expect(client.search).toHaveBeenCalledTimes(0); | ||
}); |