Created
September 17, 2019 19:58
-
-
Save tcodes0/fec9031ea094321b0a79277617db8e42 to your computer and use it in GitHub Desktop.
redux saga tests with redux-saga-test-plan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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