1

I'm trying to create a test case for App component which has the following providers.

  • Store Provider
  • Translation provider
  • redux-persist
  • Router

I'm trying to render the app which certain state, to ensure the same app is rendered. The test case passes, but I get the following as snapshot.

// Jest Snapshot v1, [link to jest docs]

exports[`This should Render App 1`] = `null`;

exports[`This should Render App 2`] = `null`;

My test case is like this,

const component = renderer.create(
         <App store={store} persistor={persistor} />,
  );
  let tree = component.toJSON();
  expect(tree).toMatchSnapshot();

tree is not null and has the rendered component. But I do not see this being written in snapshot.

npm package versions

"jest": "^22.4.4",
"react-test-renderer": "^16.4.0",

Jest doc

1 Answer 1

1

I was able to fix the issue by using .toTree() method available in react-test-renderer instead of toJSON().

toMatchSnapshot() of jest seems to accept only ReactTestRendererTree as apposed to ReactTestRendererJSON.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.