beforeEach(async () => {
const sandbox = sinon.sandbox.create()
...
})
test('/add', () => {
// how can I use sandbox here?
})
Run Code Online (Sandbox Code Playgroud)
我需要的是类似t.contextava
我们使用jest来测试我们的API并且具有非常复杂的场景.我们使用这些beforeAll函数为每个测试设置一般辅助变量,有时设置租户分离,在其他情况下,我们使用beforeEach函数为测试设置租户分离,为测试租户设置一些默认配置,...
例如,测试可能喜欢这样的东西(正如你所看到的,我们使用TypeScript来编写测试,以防万一):
let apiClient: ApiClient;
let tenantId: string;
beforeAll(async () => {
apiClient = await getClientWithCredentials();
});
beforeEach(async () => {
tenantId = await createNewTestTenant();
});
describe('describing complex test scenario', () => {
it('should have some initial state', async () => {
await checkState(tenantId);
});
it('should have some state after performing op1', async () =>{
await op1(tenantId);
await checkStateAfterOp1(tenantId);
});
it('should have some state after performing op2', async () =>{
await op2(tenantId);
await checkStateAfterOp2(tenantId);
});
it('should …Run Code Online (Sandbox Code Playgroud)