From 4c2d2235beac4308176b54b0778da2e902682f8a Mon Sep 17 00:00:00 2001 From: xidedix Date: Tue, 21 Aug 2018 17:59:33 +0200 Subject: [PATCH 1/2] test: add unit test for User.vue --- tests/unit/User.spec.js | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/unit/User.spec.js diff --git a/tests/unit/User.spec.js b/tests/unit/User.spec.js new file mode 100644 index 00000000..5253c70a --- /dev/null +++ b/tests/unit/User.spec.js @@ -0,0 +1,49 @@ +import Vue from 'vue' +import { shallowMount, mount, createLocalVue } from '@vue/test-utils' +import VueRouter from 'vue-router' + +const localVue = createLocalVue() +localVue.use(VueRouter) +const router = new VueRouter() + +import BootstrapVue from 'bootstrap-vue' +import User from '@/views/Users/User' + +localVue.use(BootstrapVue) + +describe('User.vue', () => { + it('has a name', () => { + expect(User.name).toMatch('User') + }) + it('has a created hook', () => { + expect(typeof User.data).toMatch('function') + }) + it('sets the correct default data', () => { + expect(typeof User.data).toMatch('function') + const defaultData = User.data() + expect(defaultData.fields).toEqual([{key: 'key'}, {key: 'value'}]) + }) + it('is Vue instance', () => { + const wrapper = shallowMount(User, { + localVue, + router + }) + expect(wrapper.isVueInstance()).toBe(true) + }) + it('is User', () => { + const wrapper = shallowMount(User, { + localVue, + router + }) + expect(wrapper.is(User)).toBe(true) + }) + it('renders props.caption when passed', () => { + const caption = 'User id:' + const wrapper = mount(User, { + propsData: { caption }, + localVue, + router + }) + expect(wrapper.find('div.card-header').text()).toMatch(caption) + }) +}) From d6a4b494c2fbea5d4ffffaa7c07322146a60fda3 Mon Sep 17 00:00:00 2001 From: xidedix Date: Tue, 21 Aug 2018 18:00:21 +0200 Subject: [PATCH 2/2] test: add jest config for coverage --- .gitignore | 1 + CHANGELOG.md | 4 ++++ jest.config.js | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c02b27f4..3a27222b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules package-lock.json /dist +/coverage /tests/e2e/reports/ selenium-debug.log diff --git a/CHANGELOG.md b/CHANGELOG.md index 78e9c299..bd3a93bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [vue](./README.md) version `changelog` +##### `v2.0.0-next` +- test(unit): add test for User.vue +- test: add jest config for coverage + ##### `v2.0.0-rc.0` - test(unit): add some views testing - test(e2e): add testing for mobile `sidebar-show` diff --git a/jest.config.js b/jest.config.js index 17f3de92..f503f1b3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -21,5 +21,11 @@ module.exports = { '/tests/unit/Dashboard.spec.js' ], verbose: true, - testURL: "http://localhost/" + testURL: "http://localhost/", + collectCoverage: true, + collectCoverageFrom: [ + "src/**/*.{js,vue}", + "!**/node_modules/**" + ], + coverageReporters: ["html", "text-summary"] }