We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
测试 input 组件时,如何触发事件?(change、input、focus、blbur)
describe('事件', () => { const Constructor = Vue.extend(Input) it('支持 change/input/focus/blur 事件', () => { ['change','input','focus','blur'].forEach((eventName)=>{ let vm = new Constructor({}).$mount() const callback = sinon.fake() vm.$on(eventName,callback) //触发 input 的事件 let event = new Event(eventName) Object.defineProperty( event,'target', { value:{value:'hi'}, enumerable: true } ) let inputElement = vm.$el.querySelector('input') inputElement.dispatchEvent(event) expect(callback).to.have.been.calledWith('hi') vm.$destroy() }) }) })
让组件支持 v-model 的重要之处
v-model
<input :value = "value" type="text" @input="$emit('input', event.target.value)">
兼容 v-model 后,测试用例过不了,原因是兼容之前 calledwith('event'),但兼容之后必须要触发event的值才能测试,而这时event没有这个值,在浏览器中会自动补全这个值的,但在测试时没有这个值,会报它是只读属性的错,于是需要用到
calledwith('event')
Object.defineProperty(event,'target', { value: { vaule: 'hi' }, enumerable: true })
这样可以了,原因可能是破坏了它的可读属性?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
测试 input 组件时,如何触发事件?(change、input、focus、blbur)
让组件支持
v-model
的重要之处兼容
v-model
后,测试用例过不了,原因是兼容之前calledwith('event')
,但兼容之后必须要触发event的值才能测试,而这时event没有这个值,在浏览器中会自动补全这个值的,但在测试时没有这个值,会报它是只读属性的错,于是需要用到这样可以了,原因可能是破坏了它的可读属性?
The text was updated successfully, but these errors were encountered: