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

313
Vistas
Testing redux-saga - how to wait next put (dispatch) in tests?

I'm a little bit confused. I have simple test:

test('should render', async () => {
    await act(async () => {
      renderTestApp({
        route: `/testuser`,
      });
    });

    await waitFor(() =>
      expect(screen.getByTestId('expert-page')).toBeInTheDocument(),
    );
  });

When my component is mounted I send request with saga to get user-profile:

export function* getExpert({ expertId }) {
  try {
    const payload = yield call(() => apiBaseInstance.get(`/user/${expertId}`));
    console.log(payload);
    yield put(getExpertSuccess(payload.data.user));
  } catch (error) {
    yield put(getExpertError(error.response));
  }
}

To imitate server-response I user mock service worker:

rest.get(
    `https://our-api/v1/user/testuser`,
    (req, res, ctx) => {
      return res(
        ctx.json({
          success: true,
          user: {
            id: 1
            name: 'testuser'
          },
        }),
      );
    },
  ),

When I run test I get payload from console.log inside getExpert saga (it means service worker works) but it doesn't put next action with getExpertSuccess(payload.data.user). It stops there (because of yield as I understand) and because of that my test fails (there is no user profile at state and page doesn't render). So, how can I 'run' this put in my tests?

about 4 years ago · Santiago Trujillo
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