mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Add error handling component tests
This commit is contained in:
parent
55458abbff
commit
f53d091691
@ -26,12 +26,15 @@ describe('DisableModal.vue', () => {
|
|||||||
truncate: a => a,
|
truncate: a => a,
|
||||||
},
|
},
|
||||||
$toast: {
|
$toast: {
|
||||||
success: () => {},
|
success: jest.fn(),
|
||||||
error: () => {},
|
error: jest.fn(),
|
||||||
},
|
},
|
||||||
$t: jest.fn(),
|
$t: jest.fn(),
|
||||||
$apollo: {
|
$apollo: {
|
||||||
mutate: jest.fn().mockResolvedValue(),
|
mutate: jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValueOnce({ enable: 'u4711' })
|
||||||
|
.mockRejectedValue({ message: 'Not Authorised!' }),
|
||||||
},
|
},
|
||||||
location: {
|
location: {
|
||||||
reload: jest.fn(),
|
reload: jest.fn(),
|
||||||
@ -151,6 +154,10 @@ describe('DisableModal.vue', () => {
|
|||||||
await wrapper.find('button.confirm').trigger('click')
|
await wrapper.find('button.confirm').trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
it('calls mutation', () => {
|
it('calls mutation', () => {
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
@ -174,6 +181,18 @@ describe('DisableModal.vue', () => {
|
|||||||
expect(wrapper.emitted().close).toBeTruthy()
|
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!')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -23,12 +23,15 @@ describe('ReleaseModal.vue', () => {
|
|||||||
truncate: a => a,
|
truncate: a => a,
|
||||||
},
|
},
|
||||||
$toast: {
|
$toast: {
|
||||||
success: () => {},
|
success: jest.fn(),
|
||||||
error: () => {},
|
error: jest.fn(),
|
||||||
},
|
},
|
||||||
$t: jest.fn(),
|
$t: jest.fn(),
|
||||||
$apollo: {
|
$apollo: {
|
||||||
mutate: jest.fn().mockResolvedValue(),
|
mutate: jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValueOnce({ enable: 'u4711' })
|
||||||
|
.mockRejectedValue({ message: 'Not Authorised!' }),
|
||||||
},
|
},
|
||||||
location: {
|
location: {
|
||||||
reload: jest.fn(),
|
reload: jest.fn(),
|
||||||
@ -146,6 +149,10 @@ describe('ReleaseModal.vue', () => {
|
|||||||
wrapper.find('button.confirm').trigger('click')
|
wrapper.find('button.confirm').trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
it('calls mutation', () => {
|
it('calls mutation', () => {
|
||||||
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
@ -169,6 +176,18 @@ describe('ReleaseModal.vue', () => {
|
|||||||
expect(wrapper.emitted().close).toBeTruthy()
|
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!')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user