Jest is supported both as a testing framework and a spy library. It will be auto-detected if available.
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();Jest has two similarly named options for setup files:
setupFiles: run before Jest's test framework is installedsetupFilesAfterEnv: run after it is installed
console-fail-test hooks into Jest's beforeEach and afterEach globals, which don't exist yet in setupFiles.
Listing console-fail-test/setup in setupFiles instead of setupFilesAfterEnv will fail each test suite.
Use setupFilesAfterEnv.
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",
});