Home > Software design >  Why "Branch" test coverage in Jest shows 0% coverage?
Why "Branch" test coverage in Jest shows 0% coverage?

Time:02-10

One of my test coverage is as below:

  • branch 0%
  • function 75%
  • lines 81.25%

I see total 3 lines: 16, 27 and 38 under uncovered lines. I confirm that by looking at coverage/Icov-report/index.html (WIP for improving unit test).

Would missing 3 lines of coverage cause branch coverage to be 0%? I would expect something rather than 0% but I am learning Jest so not sure.

  • Repository info: TypeScript, Node, Jest

  • Code Coverage:

    enter image description here

  • Index.html report

    enter image description here

service.ts

import { injectable } from 'inversify';
import { createLogger, format, Logger } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
import fs from 'fs';

const logDir = 'logs';

@injectable()
export default class LoggerService {
  private readonly winstonLogger: Logger;

  private static loggerService: LoggerService;

  constructor() {
    if (!fs.existsSync(logDir)) {
      fs.mkdirSync(logDir);
    }

    const dailyRotateFileTransport = new DailyRotateFile({
      filename: `${logDir}/           
  • Related