-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use newer test library to test strict mode
- Loading branch information
1 parent
bf08553
commit 2a00233
Showing
7 changed files
with
106 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,23 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { StrictMode, useEffect } from "react"; | ||
|
||
describe("Strict mode", () => { | ||
test("Runs `useEffect` twice", () => { | ||
const runs = vi.fn(); | ||
const cleanups = vi.fn(); | ||
const result = renderHook( | ||
() => { | ||
useEffect(() => { | ||
runs(); | ||
return cleanups; | ||
}, []); | ||
}, | ||
{ wrapper: StrictMode }, | ||
); | ||
expect(runs).toBeCalledTimes(2); | ||
expect(cleanups).toBeCalledTimes(1); | ||
result.unmount(); | ||
expect(runs).toBeCalledTimes(2); | ||
expect(cleanups).toBeCalledTimes(2); | ||
}); | ||
}); |
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