forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
75 lines (58 loc) · 2.13 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
/* global describe */
import Vue from 'vue'
import { shallowMount, mount } from 'packages/test-utils/src'
import { renderToString } from 'packages/server-test-utils/src'
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 isRunningChrome =
typeof navigator !== 'undefined' &&
navigator.userAgent.includes &&
navigator.userAgent.match(/Chrome/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
export const isPromise = value =>
typeof value === 'object' && typeof value.then === 'function'
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))
})
}