I have this function which needs to be unit tested,
I've wrote few specs which is working fine. But in the code-coverage it says Else path not taken
for this line if (text !== '') {}
.
I'm not sure how to test variable inside the function.
Below are few specs which I wrote.
it('should split the content correctly', inject([GenerateInlineTagsService], (service: GenerateInlineTagsService) => {
const obj = service.getView(RANGES);
expect(JSON.stringify(obj)).toEqual(JSON.stringify(inlineSplitContent));
}));
Create a new test case and pass below value to your function while testing so that else
branch would be taken:
const content = { inlineEntityRanges: [], text: '' }
Also, if possible write else
block of each if
block as while measuring branch coverage these things are required.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.