We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
29.7.0
Jest Config: module.exports = { setupFiles: [], clearMocks: true, collectCoverage: true, testEnvironment: 'jsdom', transform: { '^.+\.tsx?$': ['ts-jest', { diagnostics: false, babelConfig: true }], '^.+\.js$': 'babel-jest', 'node_modules/vue-runtime-helpers/.+\.mjs$': 'babel-jest', '.\.(vue)$': '@vue/vue2-jest' }, roots: ['/tests'], testMatch: ['**/.test.ts'], coverageThreshold: { global: { branches: 80, functions: 80, lines: 80, statements: 80 } }, // 1:解决Jest: a transform must export a process or processAsync function. moduleNameMapper: { '^.+\.(css|less|scss)$': '/jest/style.transform.js', '^@/(.)$': '/src/$1', '^@shared(.)$': '/shared$1', '^@components(.)$': '/src/components$1', '^@models(.)$': '/src/models$1', '^@utils(.)$': '/src/utils$1', '^@configs(.)$': '/src/configs$1', '^@framework(.)$': '/src/framework$1', appConfig: <rootDir>/src/configs/globalConfigs/development.config.js, 'mihoyo-game-selector': '@mihoyo-fe/mihoyo-ui/es/components/select', '\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/src/test/fileMock.js' }, transformIgnorePatterns: ['node_modules/(?!vue-runtime-helpers|@mihoyo-fe/mihoyo-ui|element-ui|history)'], // globals: { // 'ts-jest': { // tsConfig: './tsconfig.json' // } // }, // testRegex: '(/tests/.|(\.|/)(test|spec))\.tsx?$', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node', 'vue'] };
process
processAsync
<rootDir>/src/configs/globalConfigs/development.config.js
Test Code: export const getData = (a: number, b: number) => { if (a === 1) { console.log(2); return 3; // 返回值改变为2以能通过更好的测试 } if (a > 1) { console.log(1); return 2; }
return 1; };
Test Case: describe('getData', () => { it('getData测试', () => { expect(getData(1, 2)).toBe(3); }); });
branch coverage is 50%
branch coverage is 100%
Why is the above branch coverage not 50%, but 100%? because i see If (a > 1) {} is not executed
No response
System: OS: macOS 12.1 CPU: (10) arm64 Apple M1 Pro Binaries: Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node Yarn: 1.22.21 - /usr/local/bin/yarn npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm pnpm: 9.12.3 - ~/.nvm/versions/node/v20.17.0/bin/pnpm npmPackages: jest: ^29.7.0 => 29.7.0
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Version
29.7.0
Steps to reproduce
Jest Config:
module.exports = {
setupFiles: [],
clearMocks: true,
collectCoverage: true,
testEnvironment: 'jsdom',
transform: {
'^.+\.tsx?$': ['ts-jest', { diagnostics: false, babelConfig: true }],
'^.+\.js$': 'babel-jest',
'node_modules/vue-runtime-helpers/.+\.mjs$': 'babel-jest',
'.\.(vue)$': '@vue/vue2-jest'
},
roots: ['/tests'],
testMatch: ['**/.test.ts'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
// 1:解决Jest: a transform must export a
process
orprocessAsync
function.moduleNameMapper: {
'^.+\.(css|less|scss)$': '/jest/style.transform.js',
'^@/(.)$': '/src/$1',
'^@shared(.)$': '/shared$1',
'^@components(.)$': '/src/components$1',
'^@models(.)$': '/src/models$1',
'^@utils(.)$': '/src/utils$1',
'^@configs(.)$': '/src/configs$1',
'^@framework(.)$': '/src/framework$1',
appConfig:
<rootDir>/src/configs/globalConfigs/development.config.js
,'mihoyo-game-selector': '@mihoyo-fe/mihoyo-ui/es/components/select',
'\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'/src/test/fileMock.js'
},
transformIgnorePatterns: ['node_modules/(?!vue-runtime-helpers|@mihoyo-fe/mihoyo-ui|element-ui|history)'],
// globals: {
// 'ts-jest': {
// tsConfig: './tsconfig.json'
// }
// },
// testRegex: '(/tests/.|(\.|/)(test|spec))\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node', 'vue']
};
Test Code:
export const getData = (a: number, b: number) => {
if (a === 1) {
console.log(2);
return 3; // 返回值改变为2以能通过更好的测试
}
if (a > 1) {
console.log(1);
return 2;
}
return 1;
};
Test Case:
describe('getData', () => {
it('getData测试', () => {
expect(getData(1, 2)).toBe(3);
});
});
Expected behavior
branch coverage is 50%
Actual behavior
branch coverage is 100%
Why is the above branch coverage not 50%, but 100%? because i see If (a > 1) {} is not executed
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: