Skip to content

Instantly share code, notes, and snippets.

@syuji-higa
Last active October 12, 2021 15:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syuji-higa/269b329b6c391fbdc96131b6a44bfcb3 to your computer and use it in GitHub Desktop.
Save syuji-higa/269b329b6c391fbdc96131b6a44bfcb3 to your computer and use it in GitHub Desktop.
Jest - Vue.js snipets
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component)
const data = wrapper.vm.$options.asyncData()
wrapper.setData(data)
it('should be shown "test" text', () => {
expect(wrapper.text()).toBe('test')
})
it('should be setted "test" value', () => {
expect(wrapper.element.value.toBe('test')
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component)
const data = wrapper.vm.$options.asyncData({
params: {}
})
wrapper.setData(data)
it('should be shown "test" text', () => {
expect(wrapper.text()).toBe('test')
})
it('should be setted "test" value', () => {
expect(wrapper.element.value.toBe('test')
})
})
import { mount } from '@vue/test-utils'
import Component from './-Component.vue'
import ChildComponent from '~/components/modules/forms/ChildComponent.vue'
const localVue = createLocalVue()
describe('Component', () => {
let wrapper
let child
beforeEach(() => {
wrapper = mount(Component)
child = wrapper.find(ChildComponent)
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component)
it('should be shown "test" text', () => {
expect(wrapper.text()).toBe('test')
})
it('should be setted "test" value', () => {
expect(wrapper.element.value.toBe('test')
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component)
const item = wrapper.find('.item')
})
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Component from './Component.vue'
import VueRouter from 'vue-router'
const localVue = createLocalVue()
localVue.use(VueRouter)
describe('Component', () => {
const wrapper = shallowMount(Component, {
localVue
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component, {
stubs: ['invisible-component']
})
})
import { mount, createLocalVue } from '@vue/test-utils'
import Pluging from 'plugin'
import Component from '~/components/modules/forms/Component.vue'
const localVue = createLocalVue()
localVue.use(VeeValidate)
describe('Component', () => {
it('is a Vue instance', () => {
const wrapper = mount(Component, {
localVue
})
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component, {
propsData: {
text: 'test'
}
})
})
import { mount, RouterLinkStub } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = mount(Component, {
stubs: {
RouterLink: RouterLinkStub
}
})
})
import { shallowMount } from '@vue/test-utils'
import Component from './Component.vue'
describe('Component', () => {
const wrapper = shallowMount(Component, {
slots: {
default: 'test'
}
})
})
import { mount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Component from './-Component.vue'
import { state, mutations } from '~/store'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('Component', () => {
let store
let wrapper
beforeEach(() => {
store = new Vuex.Store({
modules: {
namespaced: true,
state: Object.assign(state(), {
company: 'test'
}),
mutations
}
})
wrapper = mount(Component, {
store,
localVue
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment