forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
115 lines (93 loc) · 2.68 KB
/
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* global describe, it*/
import Vue from 'vue'
import { shallow, mount } from '~vue/test-utils'
import { renderToString } from '~vue/server-test-utils'
export const vueVersion = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`)
export const isRunningJSDOM =
typeof navigator !== 'undefined' &&
navigator.userAgent.includes &&
navigator.userAgent.includes('jsdom')
export const isRunningPhantomJS =
typeof navigator !== 'undefined' &&
navigator.userAgent.includes &&
navigator.userAgent.match(/PhantomJS/i)
export const injectSupported = vueVersion > 2.2
export const attrsSupported = vueVersion > 2.2
export const listenersSupported = vueVersion > 2.3
export const functionalSFCsSupported = vueVersion > 2.4
export const scopedSlotsSupported = vueVersion > 2
const shallowAndMount = process.env.TEST_ENV === 'node'
? []
: [mount, shallow]
console.log(shallowAndMount)
const shallowMountAndRender = process.env.TEST_ENV === 'node'
? [renderToString]
: [mount, shallow]
export function describeWithShallowAndMount (spec, cb) {
if (shallowAndMount.length > 0) {
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)
}
}
itSkipIf.only = (predicate, spec, cb) => {
if (predicate) {
it.skip(spec, cb)
} else {
it.only(spec, cb)
}
}
export function itDoNotRunIf (predicate, spec, cb) {
if (predicate) {
() => {}
} else {
it(spec, cb)
}
}
itDoNotRunIf.only = (predicate, spec, cb) => {
if (!predicate) {
it.only(spec, cb)
}
}
export function describeIf (predicate, spec, cb) {
if (predicate) {
describe(spec, cb)
}
}
describeIf.only = (predicate, spec, cb) => {
if (predicate) {
describe(spec, cb)
}
}