Mock selector response twice when using provide to test redux-saga

136 Views Asked by At

I have a Saga that is using a selector twice and I wasn't able to test it using provide that is returning a responseOne and responseTwo. I tried to use selector twice that's returning different mock responses inside the provide but it only gets the first one (mockResponseOne). Is there a way on the second selector response to receive the correct response(mockResponseTwo)?

Please check the arrows with notes inside the code if my question is not so clear.

Note: I am using redux-saga-test-plan

e.g Saga

export function* mySaga(url) {
   .
   .
   .
   yield Effects.call(handleRequest, url);
    const responseOne = yield Effects.select(selectResponse);

   if (responseOne.status === "failed") {

      yield Effects.call(handleRequest, responseOne.url);

      const responseTwo = yield Effects.select(selectResponse);

      console.log(responseTwo) <==== here i am receiving the responseOne when running the saga test
   .
   .
   .
  }
}

e.g Test

import {expectSaga} from "redux-saga-test-plan";
import * as matchers from "redux-saga-test-plan/matchers";

it("should the console.log print mockResponseTwo", async () => {
        await expectSaga(
            mySaga,
            mockUrl,
        )
            .provide([
                [
                    matchers.call.fn(handleRequest),
                    mockResponseOne,
                ],
                [select(selectResponse), mockResponseOne],
                [
                    matchers.call.fn(handleRequest),
                    mockResponseTwo,
                ],
                [select(selectResponse), mockResponseTwo],  <==== here the response is not getting updated
            ])
            .call(handleRequest, mockUrl)
            .call(handleRequest, mockResponseOne.url)
        });
    });
0

There are 0 best solutions below