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)
]))
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 withyield
keyword in input/output entry.So, right value of
yield
becomesgenerator.next().value
result, andgenerator.next(RESULT)
becomes left value ofyield
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 inconst [customers, products] = yield
statement.