-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
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
Bug: 使用 wrapper.trigger('click') 无法正常触发 el-radio #2508
Labels
bug
Something isn't working
Comments
Hi @JZLeung I don't speak chinese, so I can only guess what the issue is, and answer in english, sorry. You probably need to use attachTo in that case: describe('Radio group', () => {
it('create', async () => {
const wrapper = mount(RadioComponent, { attachTo: document.body })
await nextTick()
const [radio1, radio2] = wrapper.findAll('.el-radio')
expect(radio1.classes()).toContain('is-checked')
await radio2.trigger('click')
expect(radio2.classes()).toContain('is-checked')
})
}) I think this should solve your issue. If not, open a repro on Stackblitz, and I'll take a look. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
在项目的组件中使用了 ElRadio 组件,需要进行测试。
在测试中:
无法【点击】到 radio2,使测试出错
To Reproduce
Element Plus Playground
Expected behavior
测试正常通过
Related information:
"vue": "3.4.21",
"element-plus": "2.6.0",
"vitest": "^1.5.2",
"@vue/test-utils": "^2.4.5",
Additional context
在控制台中,可以通过
document.querySelector('.el-radio').click()
正常触发,但无法通过dom.dispatchEvent()
触发,恰巧这是@vue/test-utils
中wrapper.trigger
的实现原理。The text was updated successfully, but these errors were encountered: