Housekeeping - ensure that mocks were actually called?
As the project changes, a lot of mocks can remain that are not even called in the scope of the test suite.
I wonder if in this project, we could somehow automatically detect whether a given mock was called at least once; if not, throw an error - this would help people keep their test suites lean and clean.
I wonder if in this project, we could somehow automatically detect whether a given mock was called at least once;
But sometimes mocks exist to assert that they are not called like:
test('foobar should not call callback', () => {
foobar(myMock);
expect(myMock).not.toBeCalled();
});
Perhaps a better way to ensure that unused mocks don't go unnoticed is to use a linter that reports unused variables.
@anilanar you have a point, but linter can only do so much... Imagine a convoluted mocking machinery where mocks get set up (so no "unused variables") but are never actually called. People maintain these set-ups without realising it's pointless work!