DEV Community

Discussion on: Test `history` in React Router

Collapse
 
macnick profile image
Nick Haralampopoulos

Mocking is a code smell. I will explain why.
If, for some reason, history changes the method name from push to gotoPath the test will pass because the function is mocked but the code will be broken.
Also the test does not test if it actually goes to the url /home, actually it tests if the mocked function is called with /home

Collapse
 
edfildesho profile image
edfildesHO • Edited

How do you write unit tests without mocking ever? Surely if you have to include every dependency all the time you're going to end up writing integration tests no?