forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-options.js
36 lines (33 loc) · 913 Bytes
/
merge-options.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
// @flow
function getOptions (key, options, config) {
if (options ||
(config[key] && Object.keys(config[key]).length > 0)) {
if (options instanceof Function) {
return options
} else if (Array.isArray(options)) {
return [
...options,
...Object.keys(config[key] || {})]
} else if (!(config[key] instanceof Function)) {
return {
...config[key],
...options
}
} else {
throw new Error(`Config can't be a Function.`)
}
}
}
export function mergeOptions (
options: Options,
config: Options
): Options {
return {
...options,
logModifiedComponents: config.logModifiedComponents,
stubs: getOptions('stubs', options.stubs, config),
mocks: getOptions('mocks', options.mocks, config),
methods: getOptions('methods', options.methods, config),
provide: getOptions('provide', options.provide, config)
}
}