Is there any way to clear all mocks after each data testing?
See original GitHub issueProblem
I want to clear mocks after each data testing. The problem case is following.
forAll(
row(..),
row(..),
) { x, y ->
sut.execute()
verify { mockked.handle() }
}
In this case, verifying mockked.handle()
may fail, because in this test function, single mockked instance is used.
Ugly Solution
Currently, the second best solution is just to append clearAllMocks()
after each data testing.
forAll(
row(..),
row(..),
) { x, y ->
sut.execute()
verify { mockked.handle() }
clearAllMocks() // Ugly code.
}
Is there any idea for this problem?
FYI. I used mockk.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
How to automatically reset mocks and restore spies in Jest
Configuring Jest to automatically reset / restore mocks and spies · “clearMocks”: true : resets all the mocks usage data, but keeps the...
Read more >How to reset Jest mock functions calls count before every test
One way I found to handle it: to clear mock function after each test: To add to Sum.test.js: afterEach(() => { local.getData.
Read more >Jest set, clear and reset mock/spy/stub implementation
Another way to do it is to clearAllMocks , this will mean that between tests, the stubs/mocks/spies are cleared, no matter which mock...
Read more >jest.clearAllMocks(); does not remove mock implementation ...
in my test I'm trying to clear the mocks after each test ... remove the mock implementation, and you're saying there's no way...
Read more >Mockito - Resetting Mock - Tutorialspoint
Here we've reset mock object. MathApplication makes use of calcService and after reset the mock, using mocked method will fail the test. Example....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
data-driven-testing gets mapped to actual tests, so you can use the regular beforeTest {} callback. But not in annotation-spec.
Thanks, docs updated.