We are conducting the test using the react-testing-library.
In the attached code, the first rendered component remains in state in the second rendered component.
There seems to be a scope issue with “import {isSelectedPostVar} from ‘apollo/store/post’;”.
I’m curious about the solution.
// Component
import React, { useState } from 'react';
import { isSelectedPostVar } from 'apollo/store/post';
import { useReactiveVar } from '@apollo/client';
const Post = () => {
const isSelectedPost = useReactiveVar(isSelectedPostVar);
//....
return (
//...
)
}
Test Code
function renderComponent() {
render(<Component />);
// .....
}
describe
it first test
renderComponent()
//....
it second test
renderComponent()
// The component status of the first test is maintained.