Skip to content

Latest commit

聽

History

History
48 lines (33 loc) 路 1.5 KB

Jest.md

File metadata and controls

48 lines (33 loc) 路 1.5 KB

Jest

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();

setupFiles vs. setupFilesAfterEnv

Jest has two similarly named options for setup files:

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.

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",
});