登录  /  注册
在 Vue Cypress 组件测试中复制插件
P粉725827686
P粉725827686 2023-08-30 19:44:36
[Vue.js讨论组]
<p>我正在使用 Cypress 来组件测试我的 Vue 应用程序。遵循 https://docs.cypress.io/guides/component-testing/vue/examples#Replicating-Plugins 中的代码示例会产生几个错误,如下所列:</p> <pre class="brush:php;toolbar:false;">Argument of type '(this: Context, component: ComponentOptionsWithObjectProps&lt;Readonly&lt;ComponentPropsOptions&lt;Data&gt;&gt;, unknown, {}, ComputedOptions, Record&lt;string, Function&gt;, ... 7 more ..., { ...; } | {}&gt;, options?: MountingOptions&lt;...&gt; | undefined) =&gt; Chainable&lt;...&gt;' is not assignable to parameter of type 'CommandFn&lt;&quot;mount&quot;&gt;'. Type 'Chainable&lt;{ wrapper: VueWrapper&lt;ComponentPublicInstance&lt;{ [x: number]: unknown; } &amp; { readonly length?: number | Prop&lt;unknown, unknown&gt; | null | undefined; readonly concat?: Prop&lt;unknown, unknown&gt; | { (...items: ConcatArray&lt;string&gt;[]): string[]; (...items: (string | ConcatArray&lt;...&gt;)[]): string[]; } | null | undefin...' is not assignable to type 'void | Chainable&lt;{ wrapper: VueWrapper&lt;ComponentPublicInstance&lt;ExtractPropTypes&lt;Readonly&lt;ComponentPropsOptions&lt;Data&gt;&gt;&gt;, unknown, {}, ComputedOptions, ... 6 more ..., {}&gt;&gt;; component: ComponentPublicInstance&lt;...&gt;; }&gt;'. Property 'global' does not exist on type '[options?: MountingOptions&lt;{ [x: number]: unknown; } &amp; { readonly length?: number | Prop&lt;unknown, unknown&gt; | null | undefined; readonly concat?: Prop&lt;unknown, unknown&gt; | { (...items: ConcatArray&lt;string&gt;[]): string[]; (...items: (string | ConcatArray&lt;...&gt;)[]): string[]; } | null | undefined; ... 12 more ...; toLocale...'. Cannot find name 'Vapp'. No overload matches this call. The last overload gave the following error.</pre> <p>我正在使用 TypeScript。有人可以向我提供一个工作代码片段吗?我的代码如下:</p> <pre class="brush:php;toolbar:false;">import { createPinia } from &quot;pinia&quot;; import i18n from &quot;../../src/locales/i18n&quot;; import { mount } from &quot;cypress/vue&quot;; import { h } from &quot;vue&quot;; declare global { namespace Cypress { interface Chainable { mount: typeof mount; } } } Cypress.Commands.add(&quot;mount&quot;, (component, ...args) =&gt; { args.global = args.global || {}; args.global.plugins = args.global.plugins || []; args.global.plugins.push(createPinia()); args.global.plugins.push(i18n); return mount(() =&gt; { return h(Vapp, {}, component) }, ...args); });</pre> <p>有人知道如何解决这个问题吗?在测试中使用时我如何调用这个挂载函数?</p>
P粉725827686
P粉725827686

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号