我的项目是使用vue-cordova-webpack模板构建的。我创建了一个vue组件。v-ons-input
我组件的模板内有。我需要v-ons-input
在组件的单元测试期间更改的值。我只能做后它ons-input
被编译,因为编译后,才ons-input
具有input
内部(见约OnsenUI组件编译)。问题是编译是异步执行的,当OnsenUI组件准备就绪时,我找不到任何“合法”方式来捕获事件。
我该怎么办?我创建了一个内部方法兴农间谍_compile
的ons-input
,等到它被称为:
it('test', (done) => {
const wrapper = mount(myVueComponent)
// here I can't set a value for ons-input
var spy = sinon.spy(wrapper.find('ons-input').element, '_compile')
function waitForCall(spy) {
return new Promise(function (resolve, reject) {
(function wait() {
if (spy.called) {
return resolve()
}
setTimeout(wait, 10)
})()
})
}
waitForCall(spy).then(function () {
// now ons-input is compiled and I can set a value for …
Run Code Online (Sandbox Code Playgroud)