Quasar框架的Cypress组件测试抱怨Pinia

huangapple go评论92阅读模式
英文:

Quasar Framework Cypress Component test complains about Pinia

问题

我正在使用基于Vue.js的Quasar框架,并尝试编写一个Cypress组件测试,但出现了以下错误:

  1. const pinia = createPinia()
  2. app.use(pinia)

这在生产环境中将失败。

我尝试将以下内容添加到“commands.ts”,但没有成功:

  1. Cypress.Commands.add('mount', (component) => {
  2. return mount(component, {
  3. global: {
  4. plugins: [createPinia()]
  5. }
  6. })
  7. })

在Cypress中正确地包含Pinia以使使用Pinia的任何组件测试能够正常执行的方法是什么?

英文:

I'm using the Quasar framework built on top of Vuejs and I'm trying to write a Cypress component test and I am getting the following error:

  1. [🍍]: "getActivePinia()" was called but there was no active Pinia. Did you forget to
  2. install pinia?
  3. const pinia = createPinia()
  4. app.use(pinia)
  5. This will fail in production.

I've tried adding the following to commands.ts but to no avail:

  1. Cypress.Commands.add('mount', (component) => {
  2. return mount(component, {
  3. global: {
  4. plugins: [createPinia()]
  5. }
  6. })
  7. })

What is the proper way to include pinia in cypress so that any test of a component using pinia can execute properly?

答案1

得分: 1

将以下内容翻译为中文:

  1. `cypress/support/component.ts`只需添加以下内容即可修复它
  2. ```javascript
  3. import { createPinia, setActivePinia } from 'pinia'
  4. setActivePinia(
  5. createPinia()
  6. )
英文:

Fixed it really simple. Just added the following to the cypress/support/component.ts

  1. import { createPinia, setActivePinia } from 'pinia'
  2. setActivePinia(
  3. createPinia()
  4. )

huangapple
  • 本文由 发表于 2023年7月3日 21:13:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定