react-testing
Frameworks
There are two popular test frameworks for React application, one is Enzyme
developed by Airebnb, Enzyme is used by React early days, later on React developed its own framework React Testing Library(RTT)
, Both two frameworks are specific to React Application, lack of assert, mock
which is provided by other framework like chai, sinon
and Jest developed by FackBook.
Note: chai, sinon
and Jest are independent, they can be used to test pure javascript code, they are test framework for javascript, not specific to React.
The popular way is Enzyme + Jest
which is used early by Facebook, now Facebook suggests RTT + Jest
both are developed by itself.
Enzyme vs RTT
Enzyme allows you to access the internal workings of your components. You can read and set the state, and you can mock children to make tests run faster, the render output is Component, you deal with that.
react-testing-library doesn’t give you any access to the implementation details. It renders the components and provides utility methods to interact with them(Dom output). The idea is that you should communicate with your application in the same way a user would. you act on Dom output not Component.