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
96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
import { config, shallowMount } from '@vue/test-utils'
|
|
import PostSlug from './index.vue'
|
|
import Vuex from 'vuex'
|
|
|
|
const localVue = global.localVue
|
|
|
|
config.stubs['client-only'] = '<span><slot /></span>'
|
|
|
|
describe('PostSlug', () => {
|
|
let wrapper
|
|
let Wrapper
|
|
let store
|
|
let mocks
|
|
|
|
beforeEach(() => {
|
|
store = new Vuex.Store({
|
|
getters: {
|
|
'auth/user': () => {
|
|
return {}
|
|
},
|
|
},
|
|
})
|
|
mocks = {
|
|
$t: jest.fn(),
|
|
$filters: {
|
|
truncate: a => a,
|
|
},
|
|
$route: {
|
|
hash: '',
|
|
},
|
|
// If you are mocking the router, then don't use VueRouter with localVue: https://vue-test-utils.vuejs.org/guides/using-with-vue-router.html
|
|
$router: {
|
|
history: {
|
|
push: jest.fn(),
|
|
},
|
|
},
|
|
$toast: {
|
|
success: jest.fn(),
|
|
error: jest.fn(),
|
|
},
|
|
$apollo: {
|
|
mutate: jest.fn().mockResolvedValue(),
|
|
},
|
|
}
|
|
})
|
|
|
|
describe('shallowMount', () => {
|
|
Wrapper = () => {
|
|
return shallowMount(PostSlug, {
|
|
store,
|
|
mocks,
|
|
localVue,
|
|
})
|
|
}
|
|
|
|
beforeEach(jest.useFakeTimers)
|
|
|
|
describe('test Post callbacks', () => {
|
|
beforeEach(() => {
|
|
wrapper = Wrapper()
|
|
wrapper.setData({
|
|
post: {
|
|
id: 'p23',
|
|
name: 'It is a post',
|
|
author: {
|
|
id: 'u1',
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
describe('deletion of Post from Page by invoking "deletePostCallback()"', () => {
|
|
beforeEach(() => {
|
|
wrapper.vm.deletePostCallback()
|
|
})
|
|
|
|
describe('after timeout', () => {
|
|
beforeEach(jest.runAllTimers)
|
|
|
|
it('does call mutation', () => {
|
|
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('mutation is successful', () => {
|
|
expect(mocks.$toast.success).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('does go to index (main) page', () => {
|
|
expect(mocks.$router.history.push).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|