vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.08k stars 1.17k forks source link

A check to see if all the mock functions are asserted for all the call it recieved with expected params. This check can be configured as warn and error mode. #5399

Closed paramadeep closed 1 month ago

paramadeep commented 8 months ago

Clear and concise description of the problem

This is a practice I want to enforce on my team. There is no automated way to ensure the mocks are done properly. I can give an instance for this. It is a test for controller method. My team didn't even added a request body to the test. Since we are not asserting params passed to the downstream mocked service, they have just returned the expected response.

Suggested solution

we could add a check to see if all the mock functions are asserted for all the call it received with expected parameters. This check can be set as off, warn and error mode through config. MockIt to have similar feature. It will fail the test, if any of the mock is not used in the test. Though it doesn't check if all mocks function params are asserted, java enforce using params while setting mocks.

Alternative

No response

Additional context

No response

Validations

hi-ogawa commented 8 months ago

we could add a check to see if all the mock functions are asserted for all the call it received with expected parameters.

I couldn't grasp the concept from the description. Can you provide sample code where you want to make it error/warn? Links to how other frameworks do this would also help.

sheremet-va commented 1 month ago

Since this issue hasn't been discussed for half a year, I believe it's safe to close it.