如何将变量从beforeEach挂钩传递到测试中?

时间:2018-09-19 03:45:18

标签: jestjs

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

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

我需要的是类似t.context的ava

1 个答案:

答案 0 :(得分:8)

只需声明沙箱,即可在beforeEach和test的范围内使用它:

let sandbox;

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

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