Yes
Yes
Jest, test, coverage, extends
npm create-react-app --info actually throws an error (tried on 2 clean installs on Windows 10, 64bit latest version of node). I have reproduced on 2.1.1 of create-react-app.
Error when running npx create-react-app --info :
Environment Info:
(node:9568) UnhandledPromiseRejectionWarning: Error: The system cannot find the path specified.
Create a new react app with typescript support (create-react-app v2.1 or higher required):
npx create-create-app jest-test --typescript
Add a new test file named "classes.tsx" to the src/ folder containing this code:
class Base {
public counter: number = 0;
increment() {
}
}
class Derived extends Base {
constructor(public anotherCount: number) {
super();
}
}
export { Base, Derived };
Edit the existing src/App.test.tsx file, adding this import:
import { Base, Derived } from "./classes";
.. and this extra test:
it('coverage trigger', () => {
const derivedInstance = new Derived(1);
derivedInstance.increment();
});
Edit package.json and add a new script below "scripts" to run tests with coverage:
"test:coverage": "react-scripts test --coverage"
From a command line in the project directory, run npm run test:coverage
The tests should complete without error with the --coverage option enabled.
The following error appears:
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
8 | class Derived extends Base {
> 9 | constructor(public anotherCount: number) {
| ^
10 | super();
11 | }
Note that running the tests without the --coverage option works fine.
https://github.com/rsuk/repros/tree/master/jest-typescript-coverage-issue
From a command line in the project directory, run npm run test:coverage
The issue appears to fit the description of an open issue with istanbul: Issue 237
.. which is the plugin used for coverage by jest in create-react-app
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
This bug is still present in version 3.0.0. Is there any workarround?
Are there any news?
You're waiting for Babel 7.5.0 release, which will include https://github.com/babel/babel/pull/9610
Most helpful comment
https://babeljs.io/blog/2019/07/03/7.5.0