英文:
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()
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论