gpt4 book ai didi

jestjs - 如何将变量从 beforeEach 钩子(Hook)传递给 Jest 测试?

转载 作者:行者123 更新时间:2023-12-03 14:16:25 27 4
gpt4 key购买 nike

beforeEach(async () => {
const sandbox = sinon.sandbox.create()
...
})

test('/add', () => {
// how can I use sandbox here?
})

我需要的是 t.context在艾娃

最佳答案

只需声明沙箱,使其在 beforeEach 范围内可用并进行测试:

let sandbox;

beforeEach(async () => {
sandbox = sinon.sandbox.create()
...
})

test('/add', () => {
// sandbox available for use
})

关于jestjs - 如何将变量从 beforeEach 钩子(Hook)传递给 Jest 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52397708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com