Skip to content

Commit

Permalink
add strict mode test for useReactiveVar to prevent regression
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Apr 23, 2021
1 parent 17b1383 commit 004e9ee
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/react/hooks/__tests__/useReactiveVar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { StrictMode, useEffect } from "react";
import { render, wait, act } from "@testing-library/react";

import { itAsync } from "../../../testing";
Expand Down Expand Up @@ -237,6 +237,40 @@ describe("useReactiveVar Hook", () => {
resolve();
});

itAsync("works with strict mode", async (resolve, reject) => {
const counterVar = makeVar(0);
const mock = jest.fn();

function Component() {
const count = useReactiveVar(counterVar);
useEffect(() => {
mock(count);
}, [count]);

useEffect(() => {
Promise.resolve().then(() => {
counterVar(counterVar() + 1);
});
}, []);

return (
<div />
);
}

render(
<StrictMode>
<Component />
</StrictMode>
);

await wait(() => {
expect(mock).toHaveBeenCalledWith(1);
});

resolve();
});

itAsync("works with multiple synchronous calls", async (resolve, reject) => {
const counterVar = makeVar(0);
function Component() {
Expand Down

0 comments on commit 004e9ee

Please sign in to comment.