Jest
December 4, 2025 ยท View on GitHub
Jest is supported both as a testing framework and a spy library. It will be auto-detected if available.
Setup
Use setupFilesAfterEnv to run this before setting up test files:
// jest.config.js
module.exports = {
setupFilesAfterEnv: ["console-fail-test/setup"],
};
Alternately, if you have a setup file already being run first, or you'd like to manually enable this in individual files, you can use the Node API:
// some.test.js
require("console-fail-test").cft();
Spies
Global console methods will be replaced by jest.fn() spies.
You can inspect them at runtime as usual per Jest spies.
See Jest's mock functions docs.
If you'd like to use Jasmine's spies instead of Jest's, use the Node API with the spyLibrary option:
require("console-fail-test").cft({
spyLibrary: "jasmine",
});