Skip to content

Commit

Permalink
Use newer test library to test strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
loganvolkers authored Nov 24, 2023
1 parent bf08553 commit 2a00233
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 89 deletions.
151 changes: 72 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"engines": {
"node": ">=10"

},
"scripts": {
"build": "run-s build:*",
Expand Down Expand Up @@ -112,9 +111,10 @@
"devDependencies": {
"@astrojs/language-server": "^2.3.3",
"@size-limit/preset-small-lib": "^9.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react": "^14.1.2",
"@testing-library/vue": "^8.0.1",
"@types/react": "^17",
"@types/react": "^18",
"@types/use-sync-external-store": "^0.0.6",
"@vitejs/plugin-vue": "^4.2.3",
"@vitest/coverage-v8": "^0.34.4",
"@vitest/ui": "^0.34.4",
Expand All @@ -125,13 +125,14 @@
"jotai": "^2.4.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.0",
"react": "^17",
"react-is": "^17",
"react-test-renderer": "^17",
"react": "^18",
"react-is": "^18",
"react-test-renderer": "^18",
"size-limit": "^7.0.8",
"tslib": "^2.3.1",
"tsup": "^8.0.1",
"typescript": "^4.6.3",
"use-sync-external-store": "^1.2.0",
"vitest": "^0.33.0",
"vue": "^3.3.4"
}
Expand Down
2 changes: 1 addition & 1 deletion src/react/ComponentScope.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from "@testing-library/react-hooks";
import { act, renderHook } from "@testing-library/react";
import { atom, useAtom } from "jotai";
import { createLifecycleUtils } from "../shared/testing/lifecycle";
import { ComponentScope, molecule } from "./";
Expand Down
2 changes: 1 addition & 1 deletion src/react/ScopeProvider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from "@testing-library/react-hooks";
import { act, renderHook } from "@testing-library/react";
import { atom, useAtom } from "jotai";
import React, { ReactNode, useContext, useRef, useState } from "react";
import { createLifecycleUtils } from "../shared/testing/lifecycle";
Expand Down
23 changes: 23 additions & 0 deletions src/react/sanity.test.tsx
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);
});
});
2 changes: 1 addition & 1 deletion src/react/useInjector.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from "@testing-library/react-hooks";
import { act, renderHook } from "@testing-library/react";
import { atom, getDefaultStore, useAtomValue } from "jotai";
import React from "react";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/react/useMolecule.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook } from "@testing-library/react-hooks";
import { renderHook } from "@testing-library/react";
import React, { useContext } from "react";
import { createScope, molecule, onMount, onUnmount, use } from ".";
import { ScopeProvider } from "./ScopeProvider";
Expand Down

0 comments on commit 2a00233

Please sign in to comment.