如何在测试中停止函数执行



如何测试此案例?

我在设置中有一个变量:

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
)
})

Jest(我假设大多数测试框架(将NODE_ENV环境变量设置为test。因此,您可以使用一个简单的if语句来不执行测试中的某些内容:

if(process.env.NODE_ENV !== 'test') {
const stop = await isContinuing(address)
}

最新更新