function* mySaga() {
const [customers, products] = yield all([
call(fetchCustomers),
call(fetchProducts)
])
}
I want to test all effect in jest but I get: Invalid attempt to destructure non-iterable instance
my code is:
const generator = mySaga()
expect(generator.next().value).toEqual(all([
call(fetchCustomers),
call(fetchProducts)
]))
I want to test all effect in jest but I get
To deal with an error, it is necessary to understand at first how function generator generally works, irrespective of redux-saga library. Every yield
operation performs interrupting generator instance, and point with yield
keyword in input/output entry.
So, right value of yield
becomes generator.next().value
result, and generator.next(RESULT)
becomes left value of yield
keyword. Redux-saga
effects does not perform any special work, just makes special actions objects (https://github.com/redux-saga/redux-saga/blob/master/src/internal/io.js )
So, to solve original task, just pass value to next()
generator function, which will be destructured in const [customers, products] = yield
statement.