为什么我被迫在异步中运行此代码?

时间:2017-11-06 12:14:10

标签: angular karma-jasmine

由于某种原因,我编写的代码迫使我在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);

  });

但是我的测试失败了。在异步代码肯定运行后,有谁知道我怎么能做到我的期望?

1 个答案:

答案 0 :(得分:0)

我不认为Jasmine目前支持异步。

您可以阅读更多here

另一种方法是让mochachaichai as promised一起使用。

相关问题