如果在测试期间将语句放入fakeasync()中,则My Coverage Reporter无法检测到这些语句:

describe('countWords', () => {
  it('should total number of words in string; should be 2 for "butt heaven" ', () => {
    expect(comp.countWords('butt heaven')).toBe(2);
  });
});

会被发现的很好但是…
describe('countWords', () => {
  it('should total number of words in string; should be 2 for "butt heaven" ', () => {
      fakeAsync( () => {
        expect(comp.countWords('butt heaven')).toBe(2);
      });
  });
});

会导致报应
报表未覆盖,覆盖率较低。
我该怎么解决?

最佳答案

你好像打错字了。正确的语法应该是:

it('Some description', fakeAsync(() => {
   expect(comp.countWords('butt heaven')).toBe(2);
}));

09-18 00:46