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'm trying to migrate from jest to vite and ran across this
import{takeLatest,take,call,put}from'redux-saga/effects';import{testSaga}from'redux-saga-test-plan';functionidentity(){return'value';}function*mainSaga(){constaction=yieldtakeLatest('a',identity);}describe('saga',()=>{it('works with unit tests',()=>{testSaga(mainSaga,40,2).next().takeLatest('a',identity).next().isDone();});});
I get
Expected
--------
{
'@@redux-saga/IO': true,
combinator: false,
type: 'FORK',
payload: {
context: null,
fn: [Function: takeLatest], <--- this is the part that fails equality check
args: [ 'a', [Function: identity] ]
}
}
Actual
------
{
'@@redux-saga/IO': true,
combinator: false,
type: 'FORK',
payload: {
context: null,
fn: [Function: takeLatest], <--- this is the part that fails equality check
args: [ 'a', [Function: identity] ]
}
}
This fails because the takeLatest used and imported here, is not the same as the one imported by the 'redux-saga-test-plan' package when validating the takeLatest() part of the test. However the same test works correctly in jest.
It's also easily noticeable when mocking the dependency ourselves,
which could maybe be a workaround but it seems vite can't mock dependencies of dependencies correctly? Again, note that mocking this with jest would result in both instances being mocked and the test passing.
Anyway the gist of it seems to be that when some package is imported directly in a test file and from another dependency, it results in two different instances of it, and trying to do some equality check between those two fails.
I have tried adding these packages to inline dependencies, optimizeDeps and other options I've seen around, but nothing seems to work
This fails because the takeLatest used and imported here, is not the same as the one imported by the 'redux-saga-test-plan' package when validating the takeLatest() part of the test.
It's also easily noticeable when mocking the dependency ourselves, ... which could maybe be a workaround but it seems vite can't mock dependencies of dependencies correctly?
vi.mock doesn't work for transitive import of cjs, so the workaround I mentioned above doesn't work either. Probably optimizer.ssr.enabled: true is needed there, but it doesn't look working either, so there might be an issue with vi.mock and optimized deps.
Gotcha, that makes sense and it works perfectly, thank you
vi.mock doesn't work for transitive import of cjs, so the workaround I mentioned above doesn't work either. Probably optimizer.ssr.enabled: true is needed there, but it doesn't look working either, so there might be an issue with vi.mock and optimized deps.
Yeah, about this part, this definitely feels like it should work someway, it's not hard to imagine a scenario where one would need to mock a transitive import of cjs. But not really the focus for this issue.
Describe the bug
First issue so apologies if I missed something
I'm trying to migrate from jest to vite and ran across this
I get
This fails because the
takeLatest
used and imported here, is not the same as the one imported by the 'redux-saga-test-plan' package when validating thetakeLatest()
part of the test. However the same test works correctly in jest.It's also easily noticeable when mocking the dependency ourselves,
where we get
which could maybe be a workaround but it seems vite can't mock dependencies of dependencies correctly? Again, note that mocking this with jest would result in both instances being mocked and the test passing.
Anyway the gist of it seems to be that when some package is imported directly in a test file and from another dependency, it results in two different instances of it, and trying to do some equality check between those two fails.
I have tried adding these packages to inline dependencies, optimizeDeps and other options I've seen around, but nothing seems to work
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-fxzhfs?file=test/suite.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: