For particular spec file, Andreas's is good enough. Below setup will suppress console.log
statements for all test suites,
jest --silent
(or)
To customize warn, info and debug
you can use below setup
__tests__/setup.js or jest-preload.js configured in setupFilesAfterEnv
global.console = {
log: jest.fn(), // console.log are ignored in tests
// Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log`
error: console.error,
warn: console.warn,
info: console.info,
debug: console.debug,
};
jest.config.js
module.exports = {
verbose: true,
setupTestFrameworkScriptFile: "<rootDir>/__tests__/setup.js",
};
Jest v24.x Note: setupTestFrameworkScriptFile is deprecated in favor of
setupFilesAfterEnv.
module.exports = {
verbose: true,
setupFilesAfterEnv: ["<rootDir>/__tests__/setup.js"],
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…