Add error handling component tests

This commit is contained in:
Matt Rider 2019-06-06 13:50:10 -03:00
parent 55458abbff
commit f53d091691
2 changed files with 44 additions and 6 deletions

View File

@ -26,12 +26,15 @@ describe('DisableModal.vue', () => {
truncate: a => a,
},
$toast: {
success: () => {},
error: () => {},
success: jest.fn(),
error: jest.fn(),
},
$t: jest.fn(),
$apollo: {
mutate: jest.fn().mockResolvedValue(),
mutate: jest
.fn()
.mockResolvedValueOnce({ enable: 'u4711' })
.mockRejectedValue({ message: 'Not Authorised!' }),
},
location: {
reload: jest.fn(),
@ -151,6 +154,10 @@ describe('DisableModal.vue', () => {
await wrapper.find('button.confirm').trigger('click')
})
afterEach(() => {
jest.clearAllMocks()
})
it('calls mutation', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalled()
})
@ -174,6 +181,18 @@ describe('DisableModal.vue', () => {
expect(wrapper.emitted().close).toBeTruthy()
})
})
describe('handles errors', () => {
beforeEach(() => {
wrapper = Wrapper()
// second submission causes mutation to reject
wrapper.find('button.confirm').trigger('click')
})
it('shows an error toaster when mutation rejects', async () => {
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
})
})
})
})
})

View File

@ -23,12 +23,15 @@ describe('ReleaseModal.vue', () => {
truncate: a => a,
},
$toast: {
success: () => {},
error: () => {},
success: jest.fn(),
error: jest.fn(),
},
$t: jest.fn(),
$apollo: {
mutate: jest.fn().mockResolvedValue(),
mutate: jest
.fn()
.mockResolvedValueOnce({ enable: 'u4711' })
.mockRejectedValue({ message: 'Not Authorised!' }),
},
location: {
reload: jest.fn(),
@ -146,6 +149,10 @@ describe('ReleaseModal.vue', () => {
wrapper.find('button.confirm').trigger('click')
})
afterEach(() => {
jest.clearAllMocks()
})
it('calls mutation', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalled()
})
@ -169,6 +176,18 @@ describe('ReleaseModal.vue', () => {
expect(wrapper.emitted().close).toBeTruthy()
})
})
describe('handles errors', () => {
beforeEach(() => {
wrapper = Wrapper()
// second submission causes mutation to reject
wrapper.find('button.confirm').trigger('click')
})
it('shows an error toaster when mutation rejects', async () => {
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
})
})
})
})
})