Skip to content

Latest commit

聽

History

History
52 lines (36 loc) 路 1.32 KB

Vitest.md

File metadata and controls

52 lines (36 loc) 路 1.32 KB

Vitest

Vitest is supported both as a testing framework and a spy library. It will be auto-detected if available.

Setup

In your vitest.config.ts, include console-fail-test/setup in your setupFiles:

// vitest.config.ts
import { defineConfig } from "vitest/config";

export default defineConfig({
	test: {
		setupFiles: ["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
import { describe } from "vitest";

require("console-fail-test").cft();

describe("a test", () => {
	/* ... */
});

Test Fixtures

Alternately, use extendTest to add console-fail-test as an automatic fixture, which also checks console calls from fixtures' setup and teardown:

// fixtures.js
import { extendTest } from "console-fail-test";
import { test as base } from "vitest";

export const test = extendTest(base);

Then import test from that file in your tests.

Spies

Global console methods will be replaced by vi.fn() spies. You can inspect them at runtime as usual per vitest spies. See vitest's mock functions docs.