[英]Vue test utils: '[object Object]' is not a valid selector
I'm trying to get an element by its ref
attribute from the wrapper, but it is throwing an error shown below.我试图通过它的ref
属性从包装器中获取一个元素,但它抛出了一个如下所示的错误。
According to the documentation , my usage of find
seems to be correct.根据文档,我对find
的使用似乎是正确的。
SyntaxError: '[object Object]' is not a valid selector
13 | const lis = wrapper.findAll('li');
14 |
> 15 | const a = wrapper.find({ ref: 'first' });
| ^
16 |
17 | console.log(a);
18 |
at emit (node_modules/nwsapi/src/nwsapi.js:565:17)
at _querySelectorAll (node_modules/nwsapi/src/nwsapi.js:1513:9)
at Object._querySelector [as first] (node_modules/nwsapi/src/nwsapi.js:1424:14) at VueWrapper.find (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:192 at Object.it (tests/unit/example.spec.js:15:23)
您可以通过this.$refs.first
获取您的参考值
That usage of find
is deprecated according to the current find
docs :根据当前的find
文档,不推荐使用find
:
Deprecation warning弃用警告
Using
find
to search for a Component is deprecated and will be removed.不推荐使用find
来搜索组件,并将被删除。 UsefindComponent
instead.请改用findComponent
。
And it looks like that support is completely removed now.现在看来,该支持已完全删除。 find
currently only accepts a selector string. find
当前只接受选择器字符串。
To find a component by ref
name, use findComponent
instead:要通过ref
名称查找组件,请改用findComponent
:
wrapper.findComponent({ ref: 'first' })
Support for find
is removed in Vue Test Utils 1 (for Vue2 ): vue2_find_docs . Vue Test Utils 1(适用于Vue2 )中删除了对find
的支持: vue2_find_docs 。
Vue Test Utils 2 (for Vue3 ) specifies that find
should be used for HTML elements while findComponent
should be used for Vue components: vue3_find_docs . Vue Test Utils 2(用于Vue3 )指定find
应该用于 HTML 元素,而findComponent
应该用于 Vue 组件: vue3_find_docs 。
Make sure that you are referencing the correct documentation for your Vue version and that you have the correct vue-test-utils package installed.确保您引用了适用于您的 Vue 版本的正确文档,并且您安装了正确的 vue-test-utils 包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.