You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having issues using sinon to mock things when running fast-check with jest, one cannot re-mock something with sinon that has already been mocked.
So after each test the mocks have to be restored, this can be done via either the afterEach hook for a specific property test or with the global hooks when not using fast-check/jest.
But when using fast-check/jest these hooks are not available (at least not what i could find) and the global hooks don't seem to be applied. The beforeEach/afterEach hooks provided by jest does not work as they are not executed on every single check which they need to be.
This also applies for the cleanup method from @testing-library/react which will also need to be executed after every test.
Motivation
This would be very appreciated as the omission of this feature from fast-check/jest makes testing several things a lot more complicated and annoying requiring either manually calling the cleanup stuff or constructing workarounds.
Example
Here is a bit of a contrived example.
constwhatever={bob: (n: number)=>n-10}test.prop([fc.nat()])('failing',(n)=>{sinon.replace(whatever,'bob',sinon.fake.returns(n))expect(whatever.bob(n)).toEqual(n)// sinon.restore() /* if this is called here the tests will work.})test('works',()=>{fc.assert(fc.property(fc.nat(),(n)=>{sinon.replace(whatever,'bob',sinon.fake.returns(n))expect(whatever.bob(n)).toEqual(n)}).afterEach(()=>sinon.restore()))})
This will fail with:
Property failed after 2 tests
{ seed: 1576879931, path: "1:0", endOnFailure: true }
Counterexample: [0]
Shrunk 1 time(s)
Got TypeError: Attempted to replace bob which is already replaced
The text was updated successfully, but these errors were encountered:
Definitely something worth adding. It would require te have a way to either hook into the beforeEach defined for Jest or expose one via fast-check and fill the one of Jest with it.
馃殌 Feature Request
I am having issues using sinon to mock things when running fast-check with jest, one cannot re-mock something with sinon that has already been mocked.
So after each test the mocks have to be restored, this can be done via either the
afterEach
hook for a specific property test or with the global hooks when not using fast-check/jest.But when using fast-check/jest these hooks are not available (at least not what i could find) and the global hooks don't seem to be applied. The beforeEach/afterEach hooks provided by jest does not work as they are not executed on every single check which they need to be.
This also applies for the
cleanup
method from@testing-library/react
which will also need to be executed after every test.Motivation
This would be very appreciated as the omission of this feature from fast-check/jest makes testing several things a lot more complicated and annoying requiring either manually calling the cleanup stuff or constructing workarounds.
Example
Here is a bit of a contrived example.
This will fail with:
The text was updated successfully, but these errors were encountered: