Lately at Brave I’ve been adding unit tests for our React code. For our project we use:

We also use ES6 Classes for our react code. So we’ll have a bit of code that looks like this:

Enzyme makes it really easy to test a component like this but I struggled to test the default value of the form. In the end I found a good thread on their Github repo and ended up testing it this way:

We use data-test-id any time we need a unique identifier for testing purposes. So we can just shallow render the component, call find() on the test id and then use .node.value to get the default value!

Hope that helps!