miqro · @miqro/core · @miqro/parser · @miqro/query · @miqro/jsx · @miqro/jsx-dom · @miqro/jsx-node · @miqro/request · @miqro/runner · @miqro/test · @miqro/test-http

@miqro/test

test utilities used by the miqro test runner. (deprecated)

fake

spy function.

import { fake } from "@miqro/test";

const fn = fake((x) => x * 2);

fn(5);
fn(10);

fn.callCount;        // 2
fn.callArgs[0];      // [5]
fn.callArgs[1];      // [10]
fn.returnValues[0];  // 10
fn.returnValues[1];  // 20

fn.reset();          // reset counts

requireMock

mock CJS module dependencies.

import { requireMock } from "@miqro/test";

const module = requireMock("./my-module.js", {
  "./dependency.js": {
    someFunction: () => "mocked"
  }
});

setIsolate

run tests in a forked process.

import { setIsolate } from "@miqro/test";

describe("isolated tests", () => {
  setIsolate(true);
  it("runs in own process", async () => { ... });
});

note: globalThis.test is not available in isolated processes. use node:test directly for isolated tests.

setTestTimeout

import { setTestTimeout } from "@miqro/test";

describe("slow tests", () => {
  setTestTimeout(10000);
  it("takes a while", async () => { ... });
});