Last active
October 12, 2021 15:27
-
-
Save syuji-higa/269b329b6c391fbdc96131b6a44bfcb3 to your computer and use it in GitHub Desktop.
Jest - Vue.js snipets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { shallowMount } from '@vue/test-utils' | |
import Component from './Component.vue' | |
describe('Component', () => { | |
const wrapper = shallowMount(Component) | |
const item = wrapper.find('.item') | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { shallowMount } from '@vue/test-utils' | |
import Component from './Component.vue' | |
describe('Component', () => { | |
const wrapper = shallowMount(Component, { | |
stubs: ['invisible-component'] | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { shallowMount } from '@vue/test-utils' | |
import Component from './Component.vue' | |
describe('Component', () => { | |
const wrapper = shallowMount(Component, { | |
propsData: { | |
text: 'test' | |
} | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mount, RouterLinkStub } from '@vue/test-utils' | |
import Component from './Component.vue' | |
describe('Component', () => { | |
const wrapper = mount(Component, { | |
stubs: { | |
RouterLink: RouterLinkStub | |
} | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { shallowMount } from '@vue/test-utils' | |
import Component from './Component.vue' | |
describe('Component', () => { | |
const wrapper = shallowMount(Component, { | |
slots: { | |
default: 'test' | |
} | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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