如何测试这个案例?
我在设置中有一个变量:
setup() {
const address = `${process.env.VAR_ENV}`
onMounted(async () => {
const stop = await isContinuing(address)
测试运行时,函数 await isContinuing(address) 正在执行。如何在测试运行时使函数不运行?
我的测试未定义包装变量
beforeEach(() => {
wrapper = shallowMount(App, {
})
})
describe('Dashboard', () => {
it('test to verify if initial section.', () => {
const expected = 0
expect(wrapper.findComponent({ ref: 'section' }).element.value).toBe(
expected
)
}) Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Jest(我假设大多数测试框架)将 NODE_ENV 环境变量设置为
test。因此,您可以使用简单的if语句来不在测试中执行某些操作:if(process.env.NODE_ENV !== 'test') { const stop = await isContinuing(address) }