forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-options.js
33 lines (31 loc) · 952 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
// @flow
import { normalizeStubs } from './normalize'
function getOption (option, config?: Object): any {
if (option || (config && Object.keys(config).length > 0)) {
if (option instanceof Function) {
return option
}
if (config instanceof Function) {
throw new Error(`Config can't be a Function.`)
}
return {
...config,
...option
}
}
}
export function mergeOptions (options: Options, config: Config): Options {
const mocks = (getOption(options.mocks, config.mocks): Object)
const methods = (
(getOption(options.methods, config.methods)): { [key: string]: Function })
const provide = ((getOption(options.provide, config.provide)): Object)
return {
...options,
logModifiedComponents: config.logModifiedComponents,
stubs: getOption(normalizeStubs(options.stubs), config.stubs),
mocks,
methods,
provide,
sync: !!(options.sync || options.sync === undefined)
}
}