Angular 为什么我必须以异步方式运行此代码?
出于某种原因,我写的代码迫使我在Karma中的beforeach块中运行异步代码 我对如何重写下面的代码感到困惑,这样我就可以在预期之前运行异步代码,而不必在beforeach块中执行它Angular 为什么我必须以异步方式运行此代码?,angular,karma-jasmine,Angular,Karma Jasmine,出于某种原因,我写的代码迫使我在Karma中的beforeach块中运行异步代码 我对如何重写下面的代码感到困惑,这样我就可以在预期之前运行异步代码,而不必在beforeach块中执行它 describe('SHOULD remove item whose ForecastTime is in the PAST', () => { loadStubs(); stub[2].ActivityStages[0].ForecastStartTime = '2017-09-
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);
});
但我的测试失败了。有人知道在异步代码确实运行之后,我该如何实现我的期望吗?我认为Jasmine目前不支持异步 你可以多读一些
另一种选择是与和一起使用。我认为Jasmine目前不支持异步 你可以多读一些 另一种选择是与和一起使用