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

193
Visualizações
Jest coverage tools fail

During in my react-native project, during test execution, Jest shows coverage and creates coverage reports.

Jest config:

import type {Config} from '@jest/types';

const config: Config.InitialOptions = {
    // basic params to setup test ext and env
    preset: '@testing-library/react-native',
    verbose: true,
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    roots: [
      '<rootDir>'
    ],
    // tests coverage
    collectCoverage: true,
    coverageDirectory: "__tests__/coverage",
    coverageReporters: [
        'lcov',
        'text',
    ],
    collectCoverageFrom: [
        "**/src/**/*.{js,jsx,ts,tsx}",
        "!**/src/parameters/**/*.{js,jsx,ts,tsx}",
        "!**/src/types/**/*.{js,jsx,ts,tsx}",
        "!**/src/navigationRoots/**/*.{js,jsx,ts,tsx}",
        "!**/node_modules/**",
    ],
    coverageThreshold: {
        global: {
            lines: 70,
            statements: 70
        }
    },
    // additional
    testRegex: "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    transform: {
        '^.+\\.(js|ts|tsx)$': 'babel-jest'
    },
    transformIgnorePatterns: [
        "node_modules/(?!(jest-)?@react-native|react-native|react-(native|universal|navigation)-(.*)" +
        "|@react-native-community/(.*)" +
        "|@react-navigation/(.*)" +
        "|bs-platform" +
        "|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
    ],
};

export default config;

During testing I get errors:

Consider using the "jsdom" test environment.
    
    ReferenceError: document is not defined



Consider using the "jsdom" test environment.
    
    ReferenceError: window is not defined

in files which are generated during creation of coverage folder:

coverage/lcov-report/sorter.js

coverage/lcov-report/block-navigation.js

So, in jest documentation we see that we can specify jsdom environment in file which produces error like:

/**
 * @jest-environment jsdom
 */

Ok, but here we have auto-generated files, not my test-files. How else can I fix these errors?

UPD: these errors does not appear if I delete coverage folder with all files before launching tests.so Jest creates everything good. But when I launch tests with existing "coverage" folder, during update shows errors

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

found answer on my question. when you specify jest tests folder as folder to place coverage report there, Jest considers, that coverage folder contains test.on first start when coverage folder does not exist it creates it without problems, but when you repeat coverage command, jest tries to test every js file in it. so coverage folder is needed to be excluded as test location for jest. how to do this you can find here

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