mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +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
102 lines
2.2 KiB
JavaScript
102 lines
2.2 KiB
JavaScript
import { mount } from '@vue/test-utils'
|
|
import index from './index.vue'
|
|
import Vuex from 'vuex'
|
|
|
|
const localVue = global.localVue
|
|
|
|
describe('index.vue', () => {
|
|
let store
|
|
let mocks
|
|
let getters
|
|
|
|
beforeEach(() => {
|
|
mocks = {
|
|
$t: jest.fn(),
|
|
$apollo: {
|
|
mutate: jest
|
|
.fn()
|
|
.mockRejectedValue({ message: 'Ouch!' })
|
|
.mockResolvedValueOnce({
|
|
data: {
|
|
UpdateUser: {
|
|
id: 'u1',
|
|
slug: 'peter',
|
|
name: 'Peter',
|
|
locationName: 'Berlin',
|
|
about: 'Smth',
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
$toast: {
|
|
error: jest.fn(),
|
|
success: jest.fn(),
|
|
},
|
|
}
|
|
getters = {
|
|
'auth/user': () => ({}),
|
|
}
|
|
})
|
|
|
|
describe('mount', () => {
|
|
let options
|
|
const Wrapper = () => {
|
|
store = new Vuex.Store({
|
|
getters,
|
|
})
|
|
return mount(index, { store, mocks, localVue, ...options })
|
|
}
|
|
|
|
beforeEach(() => {
|
|
options = {}
|
|
})
|
|
|
|
it('renders', () => {
|
|
expect(Wrapper().contains('div')).toBe(true)
|
|
})
|
|
|
|
describe('given form validation errors', () => {
|
|
beforeEach(() => {
|
|
options = {
|
|
...options,
|
|
computed: {
|
|
formSchema: () => ({
|
|
slug: [
|
|
(_rule, _value, callback) => {
|
|
callback(new Error('Ouch!'))
|
|
},
|
|
],
|
|
}),
|
|
},
|
|
}
|
|
})
|
|
|
|
it('cannot call updateUser mutation', () => {
|
|
const wrapper = Wrapper()
|
|
|
|
wrapper.find('#name').setValue('Peter')
|
|
wrapper.find('.ds-form').trigger('submit')
|
|
|
|
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('no form validation errors', () => {
|
|
beforeEach(() => {
|
|
options = { ...options, computed: { formSchema: () => ({}) } }
|
|
})
|
|
|
|
describe('given a new username and hitting submit', () => {
|
|
it('calls updateUser mutation', () => {
|
|
const wrapper = Wrapper()
|
|
|
|
wrapper.find('#name').setValue('Peter')
|
|
wrapper.find('.ds-form').trigger('submit')
|
|
|
|
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|