由于某种原因,我编写的代码迫使我在Karma的beforeEach块中运行异步代码。
我很困惑如何重写下面的内容,以便在我的期望之前运行异步代码而不在beforeEach块中执行它。
describe('SHOULD remove item whose ForecastTime is in the PAST', () => {
loadStubs();
stub[2].ActivityStages[0].ForecastStartTime = '2017-09-01T10:30:00.000'
beforeEach(async(setup('2017-09-01T11:30:00.000', stub)));
it('check', () => {
expect(iRepository.parent.child[1].queue.length).toBe(1);
});
});
我想做的是......
it('SHOULD remove item whose ForecastTime is in the PAST', () => {
loadStubs();
stub[2].ActivityStages[0].ForecastStartTime = '2017-09-01T10:30:00.000'
async(setup('2017-09-01T11:30:00.000', stub))
expect(iRepository.parent.child[1].queue.length).toBe(1);
});
但是我的测试失败了。在异步代码肯定运行后,有谁知道我怎么能做到我的期望?