mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
by setting up localVue with all required plugins (such as styleguide and vuex) in a separate testSetup file we can avoid doing this individually in all component tests the testSetup is executed before each test suite, so each test file gets a fresh instance of localVue
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import { mount } from '@vue/test-utils'
|
|
import TeaserImage from './TeaserImage.vue'
|
|
|
|
const localVue = global.localVue
|
|
|
|
describe('TeaserImage.vue', () => {
|
|
let wrapper
|
|
let mocks
|
|
|
|
beforeEach(() => {
|
|
mocks = {
|
|
$toast: {
|
|
error: jest.fn(),
|
|
},
|
|
$t: jest.fn(string => string),
|
|
}
|
|
})
|
|
describe('mount', () => {
|
|
const Wrapper = () => {
|
|
return mount(TeaserImage, { mocks, localVue })
|
|
}
|
|
beforeEach(() => {
|
|
wrapper = Wrapper()
|
|
})
|
|
|
|
describe('handles errors', () => {
|
|
beforeEach(() => jest.useFakeTimers())
|
|
const message = 'File upload failed'
|
|
const fileError = { status: 'error' }
|
|
|
|
it('defaults to error false', () => {
|
|
expect(wrapper.vm.error).toEqual(false)
|
|
})
|
|
|
|
it('shows an error toaster when verror is called', () => {
|
|
wrapper.vm.verror(fileError, message)
|
|
expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message)
|
|
})
|
|
|
|
it('changes error status from false to true to false', () => {
|
|
wrapper.vm.verror(fileError, message)
|
|
expect(wrapper.vm.error).toEqual(true)
|
|
jest.runAllTimers()
|
|
expect(wrapper.vm.error).toEqual(false)
|
|
})
|
|
})
|
|
})
|
|
})
|