Con*_*ila 5 vue.js jestjs vue-test-utils
我有一个专注于输入的指令。我想测试该指令。唯一的问题是我找不到如何测试输入是否聚焦的问题
这是我简单的模拟组件
<template>
<div v-directive>
<input/>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
这是我的指令:
import Vue from 'vue'
export const focusInput = () => {
return {
inserted(el: any) {
el.getElementsByTagName('input')[0].focus()
}
}
}
export default Vue.directive('focus-input', focusInput())
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
import Vue from 'vue'
import { mount , createLocalVue} from '@vue/test-utils'
import FocusInputMock from './mockComponents/FocusInputMock.vue'
import {focusInput} from '@/directives/focusInput';
const localVue = createLocalVue()
localVue.directive('directive', focusInput())
test('update content after changing state', () => {
const wrapper = mount(FocusInputMock, {
localVue
})
Vue.nextTick(function () {
expect(wrapper.find('input')) // I have to expect for this input to be focused
});
})
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?我一直在阅读Jest和Vue utils文档,但没有成功。
在安装模拟组件时,通过 { attachToDocument: true }
并尝试这个:
let input = wrapper.find('input').element
expect(input).toBe(document.activeElement);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1622 次 |
最近记录: |