I am testing the sagas in my application, and I have this fail test case that is throwing an error, even though other similar fail test cases are working
The case in question in the following
// Code to be tested
export function* fetchCollectionsAsync() {
try {
const collectionRef = firestore.collection("collections");
const snapshot = yield collectionRef.get();
const collectionsMap = yield call(
convertCollectionsSnapshotToMap,
snapshot
);
yield put(fetchCollectionsSuccess(collectionsMap));
} catch (error) {
yield put(fetchCollectionsFailure(error.message));
}
}
// Test case
it("should fire fetchCollectionsFailure if get collection fails at any point", () => {
const newGenerator = fetchCollectionsAsync();
newGenerator.next();
expect(newGenerator.throw({ message: "error" }).value).toEqual(
put(fetchCollectionsFailure("error"))
);
});
But it is throwing
FAIL src/redux/shop/shop.sagas.test.js
● fetch collections async saga › should fire fetchCollectionsFailure if get collection fails at any point
error
I also have this case for a different saga, which is pretty much the same code for the test case, but it passes
// Code to be tested
export function* isUserAuthenticated() {
try {
const userAuth = yield getCurrentUser();
if (!userAuth) return;
yield getSnapshotFromUserAuth(userAuth);
} catch (error) {
yield put(signInFailure(error));
}
}
// Test case
it('should call signInFailure on error', () => {
const newGenerator = isUserAuthenticated();
newGenerator.next();
expect(newGenerator.throw('error').value).toEqual(
put(signInFailure('error'))
);
});