【问题标题】:How to trigger keyup with enter key如何使用回车键触发 keyup
【发布时间】:2019-05-22 13:26:42
【问题描述】:

使用avavuejs 编写单元测试时,如何触发Enter keyup 事件?

例如,使用以下组件如何测试 someFunction 是否已被调用?

<input
  @keyup.enter="someFunction"
/>

【问题讨论】:

    标签: unit-testing vue.js ava


    【解决方案1】:

    我在vue-test-utils docs 上找到了。我需要打电话给input.trigger('keyup.enter');

    这是一个完整的例子:

    test('it should call add mutation', t => {
      const wrapper = mount(Todo, { localVue, store: createStore() });
      const input = wrapper.find('.todo-value');
    
      input.setValue('New todo item');
      input.trigger('keyup.enter');
    
      t.true(mutations.add.called);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多