Angular 2 - Karma coverage reporter misses statements inside fakeAsync() calls

Viewed 65

My coverage reporter fails to detect statements used if they are put inside a fakeAsync() during testing:

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

Will be detected fine but....

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

Will cause karma to report

statement not covered and lower coverage percentage.

How can I solve this?

1 Answers

Looks like you've mistyped. The correct syntax should be:

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