DEV Community

Discussion on: Writing Developer-Friendly React Unit Tests

Collapse
 
jackmellis profile image
Jack

I'm not sure if all those string literals would make things harder for typescript users.

expect(handleClick, 'was not called') vs expect(handleClick).not.toBeCalled() for me as a typescript user, the latter is not only more readable (it reads more like a sentence), but I can write faster as I get comprehensive type hinting...

Collapse
 
moubi profile image
Miroslav Nikolov

That is true. The editor will also help write tests faster but I still prefer the plain english syntax of UnexpectedJS. In that case all assertion strings are colored the same and that is easy for me to read as the eye doesn't need to jump.

Another thing I prefer is creating custom assertions to make things even more clear and less wordy.

@jackmellis do you use React Testing Library at Claimer?

Collapse
 
jackmellis profile image
Jack

We do, extensively. Having said that, we split our components based on how dumb they are. Something like a button wouldn't have any "tests", in preference of automated visual tests using something like Percy, Chromatic, Backstop, etc. 😁