Skip to content

Instantly share code, notes, and snippets.

@tcodes0
Created September 17, 2019 19:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcodes0/fec9031ea094321b0a79277617db8e42 to your computer and use it in GitHub Desktop.
Save tcodes0/fec9031ea094321b0a79277617db8e42 to your computer and use it in GitHub Desktop.
redux saga tests with redux-saga-test-plan
import loginSaga from '../Set';
import { expectSaga } from 'redux-saga-test-plan';
import yourFunction from '../../../Containers/YourFuncionHere';
global.fetch = require('jest-fetch-mock');
beforeEach(() => {
fetch.resetMocks();
});
describe('test birthday endpoint', () => {
it('get birthday from id', async () => {
const yourMockedFunction = jest.spyOn(yourFunction, 'navigate').mockImplementation(() => {});
const payload = {
username: 'seumadruga',
birthday: '856165'
};
fetch.once(
JSON.stringify({
data: {
birthdayRedable: '23/03/1882',
},
}),
);
// const reducer = (state = {}, action) => console.log({ action: JSON.stringify(action) });
await expectSaga(loginSaga)
// .withReducer(reducer)
.put({
type: 'OUTPUT_ACTION',
payload: {
data: 'foo',
},
})
.dispatch({ type: 'INPUT_ACTION' payload })
.run();
expect(yourMockedFunction).toHaveBeenCalledWith(33, 'milk');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment