Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

511
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda