两种选择:
1)使用夹具上下文对象(ctx)
fixture(`RANDOM EMAIL TESTS`)
.before(async ctx => {
/** Do this to initialize the random email and if you only want one random email
* for the entire fixture */
ctx.randomEmail = `test+${Math.floor(Math.random() * 1000)}@gmail.com`;
})
.beforeEach(async t => {
// Do this if you want to update the email between each test
t.fixtureCtx.randomEmail = `test+${Math.floor(Math.random() * 1000)}@gmail.com`;
})
test('Display First Email', async t => {
console.log(t.fixtureCtx.randomEmail);
})
test('Display Second Email', async t => {
console.log(t.fixtureCtx.randomEmail);
})
2) 在夹具之外声明一个变量
let randomEmail = '';
fixture(`RANDOM EMAIL TESTS`)
.beforeEach(async t => {
// Do this if you want to update the email between each test
randomEmail = `test+${Math.floor(Math.random() * 1000)}@gmail.com`;
})
test('Display First Email', async t => {
console.log(randomEmail);
})
test('Display Second Email', async t => {
console.log(randomEmail);
})