|
| 1 | +import Vue from 'vue' |
| 2 | +import { shallowMount, mount, createLocalVue } from '@vue/test-utils' |
| 3 | +import VueRouter from 'vue-router' |
| 4 | + |
| 5 | +const localVue = createLocalVue() |
| 6 | +localVue.use(VueRouter) |
| 7 | +const router = new VueRouter() |
| 8 | + |
| 9 | +import BootstrapVue from 'bootstrap-vue' |
| 10 | +import User from '@/views/Users/User' |
| 11 | + |
| 12 | +localVue.use(BootstrapVue) |
| 13 | + |
| 14 | +describe('User.vue', () => { |
| 15 | + it('has a name', () => { |
| 16 | + expect(User.name).toMatch('User') |
| 17 | + }) |
| 18 | + it('has a created hook', () => { |
| 19 | + expect(typeof User.data).toMatch('function') |
| 20 | + }) |
| 21 | + it('sets the correct default data', () => { |
| 22 | + expect(typeof User.data).toMatch('function') |
| 23 | + const defaultData = User.data() |
| 24 | + expect(defaultData.fields).toEqual([{key: 'key'}, {key: 'value'}]) |
| 25 | + }) |
| 26 | + it('is Vue instance', () => { |
| 27 | + const wrapper = shallowMount(User, { |
| 28 | + localVue, |
| 29 | + router |
| 30 | + }) |
| 31 | + expect(wrapper.isVueInstance()).toBe(true) |
| 32 | + }) |
| 33 | + it('is User', () => { |
| 34 | + const wrapper = shallowMount(User, { |
| 35 | + localVue, |
| 36 | + router |
| 37 | + }) |
| 38 | + expect(wrapper.is(User)).toBe(true) |
| 39 | + }) |
| 40 | + it('renders props.caption when passed', () => { |
| 41 | + const caption = 'User id:' |
| 42 | + const wrapper = mount(User, { |
| 43 | + propsData: { caption }, |
| 44 | + localVue, |
| 45 | + router |
| 46 | + }) |
| 47 | + expect(wrapper.find('div.card-header').text()).toMatch(caption) |
| 48 | + }) |
| 49 | +}) |
0 commit comments