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