Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Jest Redux Sagas fail test case failing, even though similar case passes

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'))
  );
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!