mercredi 15 août 2018

How do I snapshot test a UI change in react using jest?

I am new to snapshot testing concept. I understand that I can shallow render a component, first defining its props and state. Then I can check whether it matches a previous snapshot. That is OK.

But I don't understand how I can test UI changes. Let's say that I simulate a submit operation on a form found on my component. Submit causes a method to be called in the component and if that method throws a SubmissionError (of redux-form) the UI renders a div, but jest does not realize the change on the UI because the snapshot only covers the initial state of the UI. How can I take a second snapshot after the error div is rendered and take this snapshot into account in future tests? Or snapshot testing is not meant to handle such cases? Please advise.

Aucun commentaire:

Enregistrer un commentaire