object destructuring defaults reported as uncovered branch
See original GitHub issueDo you want to request a feature or report a bug? bug
What is the current behavior? The coverage reporter reports that the default values I assign in object destructuring are “not covered branches”.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
Simply create a code that uses object destructuring defaults and check out the coverage report:
const {
foo = 'bar'
} = this.props;
The = 'bar'
segment will be considered “uncovered” by the coverage reporter.
What is the expected behavior?
The coverage reported will ignore it, since there’s nothing to test there.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
create-react-app
config reproduces the problem just fine.
Moved from https://github.com/facebook/jest/issues/3091
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I encounter this issue. My fn:
My tests include:
getConfig()
without initial env (defaults to process.env)getConfig({})
empty envgetConfig({ KEY1: 'value', KEY2: 'value', KEY3: 'value', KEY4: undefined, KEY5: 20 })
with initial envyet the de-structuring is not covered.
Is there any solution to this?
I faced same issue while destructuring props, culprit was react defaultProps, and code will never reach destructuring defaults.