-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- create vue extend proxy to inject required template
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |