Skip to content

Commit

Permalink
#2 Initial TODO List
Browse files Browse the repository at this point in the history
- create vue extend proxy to inject required template
  • Loading branch information
kuzya-zz committed Jul 22, 2017
1 parent 5f9eb4c commit 7c92bdf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/util/vueExtendProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const DEFAULT_TEMPLATE = '<div></div>'

export default function vueExtendProxy ({extendFn, vueOptionSpec}) {
return function proxiedExtend (options) {
if (vueOptionSpec.isTemplateRequired(options)) {
options.template = DEFAULT_TEMPLATE
}

return extendFn.apply(this, arguments)
}
}
63 changes: 63 additions & 0 deletions test/unit/specs/util/vueExtendProxy.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import vueExtendProxy from 'src/util/vueExtendProxy'

describe('vueExtendProxy', () => {
let Vue
let proxiedExtend
let options
let vueOptionSpec
const sandbox = sinon.sandbox.create()

beforeEach(() => {
Vue = {
extend: sandbox.stub()
}

vueOptionSpec = {
isTemplateRequired: sandbox.stub()
}

options = {
mark: 'test',
data: [1, 2, 3]
}

proxiedExtend = vueExtendProxy({
extendFn: Vue.extend,
vueOptionSpec: vueOptionSpec
})
})

afterEach(() => {
sandbox.restore()
})

it('should check for template', () => {
options = Object.assign({}, options)

proxiedExtend(options)

expect(vueOptionSpec.isTemplateRequired).to.have.been.calledWith(options)
})

it('should add template to options if template required', () => {
vueOptionSpec.isTemplateRequired.returns(true)

proxiedExtend(options)

expect(options.template).to.equal('<div></div>')
})

it('should`t add template to options if template isn`t required', () => {
vueOptionSpec.isTemplateRequired.returns(false)

proxiedExtend(options)

expect(options.template).to.be.undefined
})

it('should call original extend', () => {
proxiedExtend(options)

expect(Vue.extend).to.have.been.calledWith(options)
})
})

0 comments on commit 7c92bdf

Please sign in to comment.