【发布时间】:2019-06-21 07:52:16
【问题描述】:
我正在使用 jest 执行 describe() 块。 在每个 test() 之间我想以同步方式执行代码,例如:
describe('matching cities to foods', () => {
// Applies only to tests in this describe block
beforeEach(() => {
return initializeFoodDatabase();
});
const city = getCity();
test('Vienna <3 sausage', () => {
expect(isValidCityFoodPair(city, 'Wiener Schnitzel')).toBe(true);
});
let city2 = getCity2();
test('San Juan <3 plantains', () => {
expect(isValidCityFoodPair(city2, 'Mofongo')).toBe(true);
});
});
function getCity(){
return 'Vienna';
}
function getCity2(){
return 'San Juan';
}
我想要的是按以下顺序执行的代码:
- 每个之前
- 获取城市
- 测试
- getCity2
- 测试
目前,测试之间的函数调用是异步执行的。怎么可能按顺序执行呢?
【问题讨论】:
-
与Question重复
标签: javascript jestjs