How to use the @lwc/jest-preset.testEnvironment function in @lwc/jest-preset

To help you get started, we’ve selected a few @lwc/jest-preset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / sfdx-lwc-jest / src / config.js View on Github external
PROJECT_ROOT,
    getModulePaths,
} = require('./utils/project.js');

function getCoveragePaths() {
    const modulePaths = getModulePaths();
    return modulePaths.map(p => {
        // convert back to forward slashes here on Windows for Jest  to be happy
        return p.replace(/\\/g, '/') + '**/*.js';
    });
}

const jestConfig = {
    rootDir: PROJECT_ROOT,
    moduleFileExtensions: ['js', 'html'],
    testEnvironment: jestPreset.testEnvironment || 'jsdom',
    transform: {
        '^.+\\.(js|html|css)$': require.resolve('@lwc/jest-transformer')
    },
    transformIgnorePatterns: [
        "/node_modules/(?!(.*@salesforce/sfdx-lwc-jest/src/lightning-stubs)/)"
    ],
    resolver: path.resolve(__dirname, './resolver.js'),
    testPathIgnorePatterns: [
      '/node_modules/',
      '/test/specs/',
    ],
    collectCoverageFrom: getCoveragePaths(),
    snapshotSerializers: [
        require.resolve('@lwc/jest-serializer')
    ],
};

@lwc/jest-preset

Jest preset configuration and stubs to help test LWC

MIT
Latest version published 3 days ago

Package Health Score

84 / 100
Full package analysis

Popular @lwc/jest-preset functions