Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Housekeeping - ensure that mocks were actually called? #25

Open
wh1t3cAt1k opened this issue May 31, 2023 · 2 comments
Open

Housekeeping - ensure that mocks were actually called? #25

wh1t3cAt1k opened this issue May 31, 2023 · 2 comments

Comments

@wh1t3cAt1k
Copy link
Contributor

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.

@anilanar
Copy link
Member

anilanar commented Jun 1, 2023

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.

@wh1t3cAt1k
Copy link
Contributor Author

@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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants