Skip to content

Commit fbb1be2

Browse files
authored
Merge pull request #119 from coreui/dev-tests
test: add some more testing
2 parents ee23ce1 + fec7016 commit fbb1be2

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
node_modules
33
package-lock.json
44
/dist
5+
/coverage
56

67
/tests/e2e/reports/
78
selenium-debug.log

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [vue](./README.md) version `changelog`
22

3+
##### `v2.0.0-next`
4+
- test(unit): add test for User.vue
5+
- test: add jest config for coverage
6+
37
##### `v2.0.0-rc.0`
48
- test(unit): add some views testing
59
- test(e2e): add testing for mobile `sidebar-show`

jest.config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ module.exports = {
2121
'<rootDir>/tests/unit/Dashboard.spec.js'
2222
],
2323
verbose: true,
24-
testURL: "http://localhost/"
24+
testURL: "http://localhost/",
25+
collectCoverage: true,
26+
collectCoverageFrom: [
27+
"src/**/*.{js,vue}",
28+
"!**/node_modules/**"
29+
],
30+
coverageReporters: ["html", "text-summary"]
2531
}

tests/unit/User.spec.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)