'Failing import in Redux Saga test

I have working saga to which I am trying to write first test:

describe('test wizard sagas', () => {
    test('fetch projects', () => {
        mockParams({
            locale: 'en-US',
        });

        const gen = fetchEshopProjects()
        const value = gen.next.value    
...

The test is failing on undefined rootSaga in middeware .run function:

import rootSaga from './store/sagas'
...
const sagaMiddleware = createSagaMiddleware()
addMiddleware(sagaMiddleware)
sagaMiddleware.run(rootSaga)

While debugging I found out that the import is only providing undefined - but I know that it is working in the live application. This is the exported rootSaga:

export default function* rootSaga() {
    yield all([
        ...
    ])
}

Why is the import undefined inside the test when it is running in live environment? How can I fix the problem?

enter image description here



Solution 1:[1]

It seems that imports work a bit differently in production and in tests. While webpack worked ok, the tests were crashing due to circular dependency. File with sagas was referencing slice from index file with middleware and the file with middleware was referencing rootsaga from the saga file. Moving the slice to another file corrected the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Faire