forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize.js
35 lines (33 loc) · 876 Bytes
/
normalize.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
import { isPlainObject } from './validators'
import { throwError } from './util'
import { VUE_VERSION } from './consts'
export function normalizeStubs (stubs = {}) {
if (stubs === false) {
return false
}
if (isPlainObject(stubs)) {
return stubs
}
if (Array.isArray(stubs)) {
return stubs.reduce((acc, stub) => {
if (typeof stub !== 'string') {
throwError('each item in an options.stubs array must be a string')
}
acc[stub] = true
return acc
}, {})
}
throwError('options.stubs must be an object or an Array')
}
export function normalizeProvide (provide) {
// Objects are not resolved in extended components in Vue < 2.5
// https://github.com/vuejs/vue/issues/6436
if (
typeof provide === 'object' &&
VUE_VERSION < 2.5
) {
const obj = { ...provide }
return () => obj
}
return provide
}