'Redux Saga mock onSuccess and onError response from the API
I'm new to redux-saga and i'm trying to make some api calls using the redux-saga as well as trying to write some unit testing using the Jest. But i'm not able to mock the onSuccess and onError reponse part in the code.
export function* login() {
try {
yield call(
request,
api_url,
{
method: "POST",
body: {
username: 'user',
password: 'pass',
},
},
{
onSuccess(response) {
store.dispatch(loginRes(response));
},
onError(error) {},
},
false
);
} catch (error) {
}
}
I'm able to cover the yield call part but I'm not able to figure out how the onSuccess and onError part can be covered.
describe('sample saga test', () => {
test('should call the login api with success response ', () => {
const generator = login();
const response = {
'status': '200',
'access': 'asdfara',
'refresh': 'dsnajfnkrufa'
};
expect(generator.next().value);
// expect(generator.next(response).value).toBe(response);
})
this is the test case that i've tried with can anyone please give some solution on how i can cover the other part.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
