forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
72 lines (56 loc) · 2.02 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
/* global describe */
import Vue from 'vue'
import { shallowMount, 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, shallowMount]
const shallowMountAndRender = process.env.TEST_ENV === 'node'
? [renderToString]
: [mount, shallowMount]
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))
})
}