これはいくつかの方法で実行できます。それぞれにプロとコンがあります。
最初の方法は、ユーザーリストをループすることです。
describe('your suite',() => {
for (let user of users) {
describe('test for user: ' + user.username,() => {
beforeAll(() => { login(user) });
it('should do a test',() => {
// test code with user
});
it('should do another test',() => {
// test code with user
});
afterAll(() => { logout(user) });
});
}
});
もう1つの方法は、コールバック関数を定義し、各ユーザーのテストを作成することです。
testCallback1 = function() {
// test code with user
}
testCallback2 = function() {
// test code with user
}
describe('test for user'),() => {
let user = users[0];
beforeAll(() => { login(user) });
it('should do a test', testCallback1);
it('should do another test', testCallback2);
afterAll(() => { logout(user) });
});
describe('test for user'),() => {
let user = users[1];
beforeAll(() => { login(user) });
it('should do a test', testCallback1);
it('should do another test', testCallback2);
afterAll(() => { logout(user) });
});
おそらくこれを行うより良い方法があります。これらはほんの数例です。