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

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

Quasar Framework Cypress Component test complains about Pinia

问题

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

const pinia = createPinia()

app.use(pinia)

这在生产环境中将失败。

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

Cypress.Commands.add('mount', (component) => {
  return mount(component, {
    global: {
      plugins: [createPinia()]
    }
  })
})

在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:

[🍍]: "getActivePinia()" was called but there was no active Pinia. Did you forget to 
install pinia?

const pinia = createPinia()

app.use(pinia)

This will fail in production.

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

Cypress.Commands.add('mount', (component) => {
  return mount(component, {
    global: {
      plugins: [createPinia()]
    }
  })
})

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

答案1

得分: 1

将以下内容翻译为中文:

`cypress/support/component.ts`只需添加以下内容即可修复它

```javascript
import { createPinia, setActivePinia } from 'pinia'

setActivePinia(
  createPinia()
)
英文:

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

import { createPinia, setActivePinia } from 'pinia'

setActivePinia(
  createPinia()
)

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:

确定