jeudi 19 septembre 2019

Jest Snapshot Testing in React Hooks

I am attempting to run a Jest snapshot test with a particular value set for one of my hook variables. I am not able to set a value for the variable in my test the way I normally would when not using hooks.

Here is the snapshot test I am running orgType is the variable of one of my hooks. Changing the orgType variable should result in the snapshot test failing however the test passes regardless of what is put in for orgType.

it('renders a snapshot of the Organization Form with orgType = hospital', () => {
  const orgType = "hospital"
  const tree = renderer.create(<OrganizationForm orgType ={orgType}/>).toJSON();
  expect(tree).toMatchSnapshot();
});

In another component I have the hook

const [orgType, setOrgType] = useState("");

I expect the snapshot test to fail when I change the orgType however the test is passing.

Aucun commentaire:

Enregistrer un commentaire