Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #5868
Closed
Open
Issue created Nov 21, 2018 by Administrator@rootContributor

Running jest test with coverage in typescript create-react-app (v2.1) throws super constructor error

Created by: rsuk

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

Jest, test, coverage, extends

Environment

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.

Steps to Reproduce

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

Expected Behavior

The tests should complete without error with the --coverage option enabled.

Actual Behavior

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.

Reproducible Demo

https://github.com/rsuk/repros/tree/master/jest-typescript-coverage-issue

From a command line in the project directory, run npm run test:coverage

Assignee
Assign to
Time tracking