Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

512
Vistas
React-Scripts and Jest - No tests found on running npm test

I am testing reducers and storage. I read the jest tutorial-react manual and it's a little different from mine, but I also found information that "react-scripts test" should also work

package.json

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "classnames": "^2.3.1",
    "faker": "^4.1.0",
    "jest": "^27.4.7",
    "miragejs": "^0.1.43",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "redux": "^4.1.2",
    "seedrandom": "^3.0.5",
    "web-vitals": "^2.1.3"
  },
  "devDependencies": {
    "jest-watch-typeahead": "^0.6.5",
    "prettier": "^2.5.1"
  }

Commands

npm test
npm test --config jest.config.js
npm test --setupFile ./src/setupTests.js
npm test --setupFiles ./src/setupTests.js

Output

Active Filters: filename .\\src\\setupTests.js/
 › Press c to clear filters.
 
Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press o to only run tests related to changed files.
 › 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.
 

On pressing "a",

No tests found, exiting with code 0

Watch Usage: Press w to show more.

./jest.config.js

// Sync object
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
    setupFiles: ['./src/setupTests.js'], 
    verbose: true,
};

module.exports = config;

./src/setupTests.js

import '@testing-library/jest-dom/extend-expect';

test('adds 1 + 2 to equal 3', () => {
    expect(1 + 2).toBe(3);
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is what the Jest documentation says about how it finds test files:

By default it looks for .js, .jsx, .ts and .tsx files inside of __tests__ folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.

Since the setupTests.js filename does not meet this criteria, Jest does not recognize it as a test file. If you rename the file to end with .test.js or move it into a __tests__ folder, Jest should be able to find it and run the test. If you need to keep the filename as is, this default behavior can be changed by setting testRegex in jest.config.js (read more about this setting here).

The setupFiles property in jest.config.js is used for setting up the environment before the tests actually run. The documentation for that setting can be found here, but it doesn't appear to be necessary to do any setup for this case based code you provided.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda