question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code Coverage report stating last closing brace as uncovered

See original GitHub issue

šŸ› Bug Report

To Reproduce

Steps to reproduce the behavior: Here is my class:

import { container, inject, injectable } from 'tsyringe';

import AppError from '@shared/errors/AppError';
import ILogger from '@shared/infra/logger/interfaces/ILogger';

import User from '../models/User';
import CheckIfUserExists from './CheckIfUserExistsUseCase';

interface IRequest {
  requestedUserId: string;
  requestingUserId: string;
  requestId: string;
}

@injectable()
class ShowUserUseCase {
  constructor(
    @inject('logger')
    private logger: ILogger
  ) {}

  public async execute({
    requestedUserId,
    requestingUserId,
    requestId,
  }: IRequest): Promise<User> {
    this.logger.log('info', 'Showing a User', {
      requestedUserId,
      requestingUserId,
      requestId,
    });

    const checkIfUserExists = container.resolve(CheckIfUserExists);
    const doesUserExist = await checkIfUserExists.execute({
      id: requestedUserId,
    });

    if (!doesUserExist) {
      this.logger.log('info', 'Requested user does not exist.', {
        requestedUserId,
        requestingUserId,
        requestId,
      });

      throw new AppError('User not found', {}, 404);
    }

    this.logger.log('info', 'User found.', {
      requestedUserId,
      requestingUserId,
      requestId,
    });

    return doesUserExist as User;
  }
}

export default ShowUserUseCase;

Here is the lcov output alongside jest

image

This happens to every single class of mine. As you can see, it is the only factor that makes this particular class not 100% on coverage of statements and lines. Also not sure why branches is not 100% covered here.

Expected behavior

I expected to a closing brace be a covered line of code.

envinfo

  System:
    OS: Linux 4.19 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    jest: 26.6.1 => 26.6.1 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, Nov 1, 2020

Ah no wait! It works on Node 14 correctly, but with node 12 I get the same result as you do. Probably something to do with babel’s transform then. I don’t think it’s an issue with Jest, tho?

Closing, but if you still think it’s a bug in Jest we can reopen

0reactions
github-actions[bot]commented, May 11, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

code coverage issue with brace | Apple Developer Forums
I've got a Swift function for which Xcode is showing 0 passes in code coverage. The line is a closing brace (highlighted in...
Read more >
Why is a closing brace showing no code coverage?
The issue boils down to the return statement not allowing it to fall down to the empty else statement, thus indicating the code...
Read more >
Code coverage colouring is red highlighting a test method ...
The thing is, it only highlights the closing bracet of the method! Pressumably, it is because the test method throws an exception, thus...
Read more >
How to stop reporting uncovered line with only braces?
I have unit tests covering the if and else parts, but SonarQube reports that there's no coverage for the line that has only...
Read more >
Closing braces sometimes not being included in code ...
Hi Jim, Unfortunately, there's a known issue with closing braces in dotCover: dotCover considers as uncovered closing braces in methods thatĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found