-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(solid-query): Add test for transition (#4224)
* test(solid-query) Add test for transition * change! * chore(solid-js) update to most recent version and enable test * Delete change Co-authored-by: Jedrzej Sadowski <jedrzej.sadowski@justeattakeaway.com> Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
- Loading branch information
1 parent
222ec62
commit f5fb92c
Showing
4 changed files
with
112 additions
and
14 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,58 @@ | ||
import { fireEvent, render, screen, waitFor } from 'solid-testing-library' | ||
|
||
import { createSignal, Show, startTransition, Suspense } from 'solid-js' | ||
import { createQuery, QueryCache, QueryClientProvider } from '..' | ||
import { createQueryClient, queryKey, sleep } from './utils' | ||
|
||
describe("useQuery's in Suspense mode with transitions", () => { | ||
const queryCache = new QueryCache() | ||
const queryClient = createQueryClient({ queryCache }) | ||
|
||
it('should render the content when the transition is done', async () => { | ||
const key = queryKey() | ||
|
||
function Suspended() { | ||
const state = createQuery(key, async () => { | ||
await sleep(10) | ||
return true | ||
}) | ||
|
||
return <Show when={state.data}>Message</Show> | ||
} | ||
|
||
function Page() { | ||
const [showSignal, setShowSignal] = createSignal(false) | ||
|
||
return ( | ||
<div> | ||
<button | ||
aria-label="toggle" | ||
onClick={() => | ||
startTransition(() => setShowSignal((value) => !value)) | ||
} | ||
> | ||
{showSignal() ? 'Hide' : 'Show'} | ||
</button> | ||
<Suspense fallback="Loading"> | ||
<Show when={showSignal()}> | ||
<Suspended /> | ||
</Show> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
render(() => ( | ||
<QueryClientProvider client={queryClient}> | ||
<Page /> | ||
</QueryClientProvider> | ||
)) | ||
|
||
await waitFor(() => screen.getByText('Show')) | ||
fireEvent.click(screen.getByLabelText('toggle')) | ||
|
||
await waitFor(() => screen.getByText('Message')) | ||
// verify that the button also updated. See https://github.com/solidjs/solid/issues/1249 | ||
await waitFor(() => screen.getByText('Hide')) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.