小编Lan*_*ana的帖子

如何确定OnsenUI组件是否在单元测试中被编译

我的项目是使用vue-cordova-webpack模板构建的。我创建了一个vue组件。v-ons-input我组件的模板内有。我需要v-ons-input在组件的单​​元测试期间更改的值。我只能做后它ons-input被编译,因为编译后,才ons-input具有input内部(见约OnsenUI组件编译)。问题是编译是异步执行的,当OnsenUI组件准备就绪时,我找不到任何“合法”方式来捕获事件。

我该怎么办?我创建了一个内部方法兴农间谍_compileons-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)

javascript unit-testing onsen-ui vue.js

8
推荐指数
1
解决办法
137
查看次数

标签 统计

javascript ×1

onsen-ui ×1

unit-testing ×1

vue.js ×1