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?