Line in constructor of class that extends another class, calls super, and has a return statement erroneously marked as uncovered
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
* **Version**: v14.15.4
* **Platform**: Linux 5.4.0-58-generic #64~18.04.1-Ubuntu SMP Wed Dec 9 17:11:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
## 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_:
```js
import B from './B.js'
export default class A extends B {
constructor () {
super()
return
}
}
```
2. Create class `B` in _B.js_:
```js
export default class B {}
```
3. Create the test in `test.js`:
```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()
})
```
3. 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:
```js
import B from './B.js'
export default class A extends B {
constructor () {
super()
/* c8 ignore next 2 */
return
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.