forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utils.js
81 lines (65 loc) · 1.96 KB
/
test-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* global describe, it*/
import Vue from 'vue'
import { shallow, mount, renderToString } from '~vue-test-utils'
export const vueVersion = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`)
export const isRunningJSDOM = navigator.userAgent.includes && navigator.userAgent.includes('jsdom')
export function injectSupported () {
return vueVersion > 2.2
}
export function attrsSupported () {
return vueVersion > 2.2
}
export function listenersSupported () {
return vueVersion > 2.3
}
export function functionalSFCsSupported () {
return vueVersion >= 2.5
}
const shallowAndMount = [mount, shallow]
const shallowMountAndRender = isRunningJSDOM
? [mount, shallow, renderToString]
: [mount, shallow]
export function describeWithShallowAndMount (spec, cb) {
shallowAndMount.forEach(method => {
describe(`${spec} with ${method.name}`, () => cb(method))
})
}
describeWithShallowAndMount.skip = function (spec, cb) {
shallowAndMount.forEach(method => {
describe.skip(`${spec} with ${method.name}`, () => cb(method))
})
}
describeWithShallowAndMount.only = function (spec, cb) {
shallowAndMount.forEach(method => {
describe.only(`${spec} with ${method.name}`, () => cb(method))
})
}
export function describeWithMountingMethods (spec, cb) {
shallowMountAndRender.forEach(method => {
describe(`${spec} with ${method.name}`, () => cb(method))
})
}
describeWithMountingMethods.skip = function (spec, cb) {
shallowMountAndRender.forEach(method => {
describe.skip(`${spec} with ${method.name}`, () => cb(method))
})
}
describeWithMountingMethods.only = function (spec, cb) {
shallowMountAndRender.forEach(method => {
describe.only(`${spec} with ${method.name}`, () => cb(method))
})
}
export function itSkipIf (predicate, spec, cb) {
if (predicate) {
it.skip(spec, cb)
} else {
it(spec, cb)
}
}
export function itDoNotRunIf (predicate, spec, cb) {
if (predicate) {
() => {}
} else {
it(spec, cb)
}
}