Questions tagged [redux-saga-test-plan]

redux-saga-test-plan is a library for unit testing and integration testing code written with redux-saga, which is a front-end library for application state management written in JavaScript, commonly used with React. This tag should be used for question related to writing tests with this library.

The library redux-saga-test-plan is for unit testing and integration testing code written with redux-saga, which is a front-end library for application state management written in JavaScript, commonly used with React.

This tag should be used for question related to writing tests with this library.

The official documentation for redux-saga-test-plan can be found at http://redux-saga-test-plan.jeremyfairbank.com/

The source can be found at https://github.com/jfairbank/redux-saga-test-plan

48 questions
1
vote
1 answer

redux-saga-test-plan Failing Assert with exact expected and actual

I have a createPostSaga which POSTs to my API and I am trying to test it. This is the saga: export function* createPostSaga(action) { const token = yield select(selectToken); const headerParams = { Authorization: `JWT ${token}` }; const…
CHBresser
  • 185
  • 2
  • 2
  • 15
1
vote
1 answer

Mocking an action payload with redux-saga-test-plan

Given a saga that operates over the action payload, where action has been passed in by takeLatest e.g. export function* mySaga(action) { try { yield all(action.payload.items.map(p => call(doSomething, p))); } yield…
Bayard Randel
  • 9,930
  • 3
  • 42
  • 46
1
vote
1 answer

Unit tests on react with Jest: how to mock an action from different feature?

I am currently doing unit tests on with Jest on one of my react services (using redux-saga). These services call API, selectors and actions which are outside from the other API, selectors, and actions specific to this service. So to mock these…
printfx000
  • 51
  • 3
0
votes
0 answers

mock takeEvery in redux testing

export function* saga() { yield* takeEvery(somethingActions.doSomethingElse, pollSaga); } I'm trying to write a test for somethingActions.doSomethingElse, which is fine and all, but I have this line that kicks off pollSaga. I would like to mock…
0
votes
0 answers

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

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…
0
votes
1 answer

Using redux-saga-test-plan, I have a dispatch action that takes a function as an argument. This makes the test always fail

I have a saga that yields a put. One of the arguments to that put is a function object. I've copied the saga function only as far as it is relevant: function* updateTaskTimeCancelledTimeRejectedSuccess(action) { const {payload} = action.data …
0
votes
0 answers

redux saga function is called twice

I have a generator function named addCart. And I have one generator function named watcher. So I have console log('0') in my addCart. If I dispatch it now, why I see in my console two times 0? 0 0 and then I get two other payloads? (If I dispatch)…
0
votes
1 answer

testing redux saga callback function

In the saga function, after success, I am doing a callback. I tried to cover this in testing but its not getting covered. can anyone suggest some way to cover those fields. export function* submitSavedDataWorker(action) { try { const…
Rahul N R
  • 23
  • 1
  • 4
0
votes
0 answers

React-Redux action is getting dispatched twice

On button click my redux action is getting dispatched twice. I have tried many possible ways but still no solution. In Component:
0
votes
1 answer

Mocking invoked saga

I would like to mock a value returned for an external saga using redux-saga-test-plan. export function* callApi(endpoint, method, params) { let { accessToken } = yield select(authSelector); const { apiUrl } = yield select(envSelector); if…
0
votes
1 answer

Should my reducer handle @@redux-saga-test-plan/INIT action?

I'm using redux-saga-test-plan to test my sagas for redux-saga. While debugging my tests I've noticed that my reducer receives one unexpected action, with type === "@@redux-saga-test-plan/INIT". I do not see any mention of this…
TMG
  • 2,620
  • 1
  • 17
  • 40
0
votes
0 answers

Does selecting global state in generator make the function to be impure?

When i used to select the current state in a saga generator, does this make the function to be impure function, and by this it will affect the way in uni testing, const currentState = state => state; function* doLogin(){ const state = yield…
M1M6
  • 915
  • 3
  • 17
  • 33
0
votes
1 answer

I'm having trouble using react-saga-test-plan

The following code is a demo given by the official import { call, put, take } from 'redux-saga/effects' import { expectSaga } from 'redux-saga-test-plan' function * userSaga (api) { const action = yield take('REQUEST_USER') const user = yield…
yanyang
  • 1
  • 2
0
votes
1 answer

How to test multiple takeEvery in sagas?

I have the following saga that listens different type of action: export default function *() { yield takeEvery('FOO', listener) yield takeEvery('BAR', listener2) yield takeEvery('HELLO_WORLD', listener3) } Essentially, this saga has a…
Alejandro
  • 2,266
  • 6
  • 35
  • 63
0
votes
1 answer

Testing redux saga with dynamic payloads from requests

I'm trying to understand tests with redux-saga-test-plan, but I'm kinda stuck with dynamic payloads. Here's my saga: function* getCheapCars() { try { const response = yield call(fetch, '/api/home') const cars = yield…
MadMatt
  • 119
  • 6
  • 14