Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
How to test all effect with redux-saga-test-plan. All effect do not match

I have a generator that I want to cover with unit-test

export default function* gatawayFlow() {
  yield all([
    takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
    takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
  ]);
}

I wrote a simple test with redux-sag-test-plan

import {expectSaga, testSaga} from 'redux-saga-test-plan';
import gatawayFlow, {getGatewaysFlow, selectGatewayFlow} from '../logic/sagas';
import * as actions from '../logic/actions';
import * as actionTypes from '../logic/actionTypes';
import {takeEvery, takeLatest} from '@redux-saga/core/effects';

// Unit-test
describe('Unit tests', () => {
  test('Test all effect', () => {
    const saga = testSaga(gatawayFlow);
    saga
        .next()
        .all({
          [actionTypes.GET_GATEWAYS_REQUEST]: takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
          [actionTypes.SELECT_GATEWAY_REQUEST]: takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow)
        })
        .next()
        .isDone();
    // expect(gatawayFlow().next().value).toEqual(all([
    //   takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
    //   takeEvery(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
    // ])); ---> THIS TEST WORKS CORRECT
  });
});

And my test didn't pass. I have this error in my terminal. Any ideas how I can solve it?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use all([...effects]) - parallel effects instead of a dictionary Object of the form {label: effect, ...}

saga.ts:

import { all, takeEvery, takeLatest } from 'redux-saga/effects';

export const actionTypes = {
  GET_GATEWAYS_REQUEST: 'GET_GATEWAYS_REQUEST',
  SELECT_GATEWAY_REQUEST: 'SELECT_GATEWAY_REQUEST',
};

export function* getGatewaysFlow() {}
export function* selectGatewayFlow() {}

export default function* gatawayFlow() {
  yield all([
    takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
    takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
  ]);
}

saga.test.ts:

import { expectSaga, testSaga } from 'redux-saga-test-plan';
import gatawayFlow, { actionTypes, getGatewaysFlow, selectGatewayFlow } from './saga';
import { takeEvery, takeLatest } from '@redux-saga/core/effects';

describe('Unit tests', () => {
  test('Test all effect', () => {
    const saga = testSaga(gatawayFlow);
    saga
      .next()
      .all([
        takeEvery(actionTypes.GET_GATEWAYS_REQUEST, getGatewaysFlow),
        takeLatest(actionTypes.SELECT_GATEWAY_REQUEST, selectGatewayFlow),
      ])
      .next()
      .isDone();
  });
});

test result:

 PASS   redux-saga-examples  packages/redux-saga-examples/src/stackoverflow/69252089/saga.test.ts
  Unit tests
    ✓ Test all effect (2 ms)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |      75 |      100 |      20 |     100 |                   
 saga.ts  |      75 |      100 |      20 |     100 |                   
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.553 s
Ran all test suites related to changed files.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda