method
test.Test.runIf
Referenced types
interface Test<T extends ReadonlyArray<unknown>>
Runs a test.
test("can check if using Bun", () => {
expect(Bun).toBeDefined();
});
test("can make a fetch() request", async () => {
const response = await fetch("https://example.com/");
expect(response.ok).toBe(true);
});
test("can set a timeout", async () => {
await Bun.sleep(100);
}, 50); // or { timeout: 50 }- afterAll: (fn: () => void | Promise<unknown> | (done: (err?: unknown) => void) => void, options?: HookOptions) => void
- afterEach: (fn: () => void | Promise<unknown> | (done: (err?: unknown) => void) => void, options?: HookOptions) => void
- aroundEach: (fn: (runTest: () => Promise<void>, context: TestContext, suite: TestSuite) => unknown, options?: HookOptions) => void
- beforeAll: (fn: () => void | Promise<unknown> | (done: (err?: unknown) => void) => void, options?: HookOptions) => void
- beforeEach: (fn: () => void | Promise<unknown> | (done: (err?: unknown) => void) => void, options?: HookOptions) => void
- extend: ExtendTest<object>
Returns a
testwhose callbacks receive the TestContext withfixturesadded to it.A fixture is set up for the tests that destructure it, and for the returned
test'sbeforeEach()/afterEach()hooks that destructure it. It's torn down after the test.const test = base.extend<{ server: Server }>({ server: async ({}, use) => { const server = Bun.serve({ port: 0, fetch: () => new Response("ok") }); await use(server); await server.stop(); }, }); test("responds", async ({ server }) => { expect(await (await fetch(server.url)).text()).toBe("ok"); }); - condition: boolean
Runs the test concurrently with other concurrent tests, if
conditionis true.@param conditionif the test should run concurrently
- table: readonly Row[]
Like
each(), but an array row is passed as one argument instead of being spread, and the second argument is the TestContext.test.for([[1, 2, 3]])("%i + %i = %i", ([a, b, sum], { expect }) => { expect(a + b).toBe(sum); });