我是组件测试和赛普拉斯的新手。我一直按照官方文档和示例对我的项目进行一些基本的组件测试。最终,我偶然发现了一个案例,我想测试我编写的一个简单组件,该组件接受单个槽(default
),并且由于它与存储库中提供的示例非常相似@cypress/vue
,所以我冒昧地复制了代码并将其调整为我的喜好。
然而,虽然第一个测试通过并安装没有问题,但当我尝试安装正在测试的组件并将其传递给默认插槽时,我收到类型错误Cannot convert undefined or null to object
。从那时起,我浏览了 Vue 和 Vue-Testing 示例,但我似乎没有弄清楚在调用 mount 函数时我做错了什么。下面是我的代码片段,供那些可以在这方面帮助我的人参考。
基本按钮
<template>
<a role="button" class="btn btn-primary">
<slot />
</a>
</template>
Run Code Online (Sandbox Code Playgroud)
BaseButton.spec.ts
import BaseButton from '@/components/BaseButton.vue'
import { mount } from '@cypress/vue'
describe('BaseButton', () => {
context('when slots are not passed', () => {
it('renders nothing', () => {
mount(BaseButton)
cy.get('a').should('have.text', '')
})
})
context('when slots are passed', () => {
it('renders slots', () => {
mount(BaseButton, {
slots: {
default: …
Run Code Online (Sandbox Code Playgroud) 我已经使用了settings.json
一段时间来在我的不同机器(恰好是 Linux、macOS 和 Windows)之间共享一些项目设置。我使用的设置之一是“python.pythonPath”,它指向.venv
该Poetry
工具创建的解释器。由于 virtualenvs 的 Windows 和基于 Linux 的操作系统路径不同,因此我需要使用正确的路径设置环境变量,例如:CLAYMEMOIRS_INTERPRETER
。
我开始注意到一个问题,每当我启动 Visual Studio Code 时,我的:
{
...
"python.pythonPath" : "${env:CLAYMEMOIRS_INTERPRETER}"
}
Run Code Online (Sandbox Code Playgroud)
自动替换为:
{
...
"python.pythonPath" : "c:\\GitHub\\claymemoirs\\.venv\\Scripts\\python.exe"
}
Run Code Online (Sandbox Code Playgroud)
这是我的环境变量的值。有人知道我如何防止这种行为吗?我没有做任何更新或更改任何插件。