How to pass variable from beforeEach hook to tests in jest?

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


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

What I need is something like t.context in ava

36490 次浏览

只需声明 sandbox,这样它就可以在 before Every 和 test 的范围内使用:

let sandbox;


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


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