Skip to content

Instantly share code, notes, and snippets.

@Sidnioulz
Created November 30, 2021 13:33
Show Gist options
  • Save Sidnioulz/ef693ea43dd63a6d172342496a78e7ad to your computer and use it in GitHub Desktop.
Save Sidnioulz/ef693ea43dd63a6d172342496a78e7ad to your computer and use it in GitHub Desktop.
Sample saga test
describe('loginSaga', () => {
it('logs a user in when the email and password are recognised', async () => {
const { store, dispatched } = configureStore()
/* Arrange */
const expirationDate = getFutureDate({ minute: 15 })
mockAxiosSuccess({ expirationDate }) // /auth/login
mockAxiosSuccess(annieErnaux) // /auth/fetchCurrentUser
/* Act */
store.dispatch(login({ ...goodData }))
/* Assert */
await expectAction(dispatched, { type: LOGIN_SUCCESS })
expect(store.getState()).toMatchObject({
auth: {
error: null,
expirationDate,
loginPending: false,
user: annieErnaux,
},
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment