Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!