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

311
Views
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
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!