Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line in constructor of class that extends another class, calls super, and has a return statement erroneously marked as uncovered #290

Open
aral opened this issue Feb 26, 2021 · 0 comments
Labels

Comments

@aral
Copy link

aral commented Feb 26, 2021

Summary

When:

  1. class A extends B and
  2. class A’s constructor calls super() and
  3. class A constructor contains a return statement

Then:

The line containing the closing brace of the constructor method is shown as uncovered by c8.

To reproduce

(Testing with latest c8, tape and tap-nyc in a "type": "module" node project.)

  1. Create class A in A.js:
import B from './B.js'

export default class A extends B {
  constructor () {
    super()
    return
  }
}
  1. Create class B in B.js:
export default class B {}
  1. Create the test in test.js:
import test from 'tape'
import A from './A.js'

test('bug', t => {
  const a = new A()
  t.true(a instanceof A, 'the returned object is as expected')
  t.end()
})
  1. Run coverage:
 npx c8 node test.js | npx tap-nyc

What should happen

Coverage should be 100%

What actually happens

Class A’s coverage is 66.67%, with line 7 flagged as uncovered.

Workaround

Ignore the return statement and the line after it. e.g., modify the constructor in class A from the above example to match the following:

import B from './B.js'

export default class A extends B {
  constructor () {
    super()
    /* c8 ignore next 2 */
    return
  }
}
@bcoe bcoe added the bug label Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants