Test that the router pushes to the same url with a right or wrong email.

This commit is contained in:
Hannes Heine 2021-08-10 14:46:51 +02:00
parent 5300bc8e1a
commit 14bb60ac84

View File

@ -77,9 +77,6 @@ describe('ForgotPassword', () => {
describe('invalid Email', () => { describe('invalid Email', () => {
beforeEach(async () => { beforeEach(async () => {
mockAPIcall.mockRejectedValue({
message: 'error',
})
await form.find('input').setValue('no-email') await form.find('input').setValue('no-email')
await flushPromises() await flushPromises()
}) })
@ -94,27 +91,56 @@ describe('ForgotPassword', () => {
}) })
describe('valid Email', () => { describe('valid Email', () => {
beforeEach(async () => { beforeEach(() => {
mockAPIcall.mockResolvedValue({ form.find('input').setValue('user@example.org')
message: 'error', })
describe('calls the API', () => {
describe('sends back error', () => {
beforeEach(async () => {
mockAPIcall.mockRejectedValue({
message: 'error',
})
await form.trigger('submit')
await flushPromises()
})
it('pushes to "/thx/password"', () => {
expect(mockAPIcall).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'user@example.org',
},
}),
)
expect(mockRouterPush).toHaveBeenCalledWith('/thx/password')
})
}) })
await form.find('input').setValue('user@example.org')
await form.trigger('submit')
await flushPromises()
})
it('calls the API', () => { describe('success', () => {
expect(mockAPIcall).toBeCalledWith( beforeEach(async () => {
expect.objectContaining({ mockAPIcall.mockResolvedValue({
variables: { data: {
email: 'user@example.org', sendResetPasswordEmail: {
}, state: 'success',
}), },
) },
}) })
await form.trigger('submit')
await flushPromises()
})
it('pushes "/thx/password" to the route', () => { it('pushes to "/thx/password"', () => {
expect(mockRouterPush).toHaveBeenCalledWith('/thx/password') expect(mockAPIcall).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'user@example.org',
},
}),
)
expect(mockRouterPush).toHaveBeenCalledWith('/thx/password')
})
})
}) })
}) })
}) })