How to use @lwc/jest-preset - 1 common examples

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 1 month ago

Package Health Score

87 / 100
Full package analysis

Popular @lwc/jest-preset functions