Undoware
Undoware

Reputation: 99

Inspecting React component state in Jest

I have a React container-pattern component with some complex logic which manipulates its internal state via this.setState(), etc. I'd like to test both the methods attached to the component which manipulate this state, and the value of this.state before and after they run. I've been poring over the Jest docs and while I see lots of examples of e.g. snapshotting, I specifically need to test this container in the abstract, apart from its display/rendering.

What do folks recommend? What have I missed? :)

Upvotes: 0

Views: 1159

Answers (1)

vijayst
vijayst

Reputation: 21836

Jest is a test runner, mocking framework and has snapshot testing. Snapshot testing tests only the final render.

To test state, I recommend using Jest along with Enzyme. Enzyme allows to simulate actions, inspect state, etc.

Upvotes: 2

Related Questions