Skip to content

Default TypeScript CRA installation doesn't run Jest test with npm run test #11872

@dfberry

Description

@dfberry

Describe the bug

Jest test run finds no test

To reproduce

  1. create app

    npx create-react-app my-app --template typescript
    
  2. run tests

    cd my-app && npm run test
    

Run results in terminal

No tests found related to files changed since last commit.
Press a to run all tests, or run Jest with --watchAll.

Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.

Fix

To fix this issue, create __tests__ directory under src and move App.test.tsx into that directory.

Did you try recovering your dependencies?

No this was a default ts install.

Which terms did you search for in User Guide?

Your original sample should work.

Environment

Tried mac os and devcontainer (linux).

Steps to reproduce

  1. create app

    npx create-react-app my-app --template typescript
    
  2. run tests

    cd my-app && npm run test
    

Expected behavior

App.test.tsx file is found and its test is run.

Actual behavior

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.

Reproducible demo

Repo with example

Fix

To fix this issue, create __tests__ directory under src and move App.test.tsx into that directory. Fix test file import statement to the correct location of App in parent dir.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions