I'm executing a describe() block using jest. between each test() I'd like to execute code in a synchronous manner, for example:
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';
}
What I want is the code to be executed in the following sequence:
- beforeEach
- getCity
- test
- getCity2
- test
Currently, the function calls between tests are being executed asynchronously. How is it possible to execute it in a sequential manner?