All files getMergedOptions.js

100% Statements 6/6
100% Branches 2/2
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                    24x 24x 24x 22x   11x   24x        
import cloneDeep from 'lodash/cloneDeep'
import flattenMixinTree from './flattenMixinTree'
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
 
/**
 * @param {Vue} vm - vue instance
 * @param {string} prop - option name
 */
export default (vm, prop) => {
  let options = cloneDeep(get(vm, `$options.${prop}`, {}))
  const mixins = get(vm, '$options.mixins', [])
  flattenMixinTree(mixins)
    .filter((mixin) => mixin[prop])
    .forEach((mixin) => {
      options = Object.assign(options, mixin[prop])
    })
  return (isEmpty(options))
    ? null
    : options
}