Packages
    Preparing search index...

    Module @mcansh/vitest-response-matchers

    @mcansh/vitest-response-matchers

    Response assertion matchers for vitest

    npm install @mcansh/vitest-response-matchers
    
    // tsconfig.json
    {
    "compilerOptions": {
    "types": ["@mcansh/vitest-response-matchers/client"]
    }
    }
    // vitest.setup.ts
    import "@mcansh/vitest-response-matchers";

    Check if the response has a specific status code.

    let response = new Response("Hello World!");

    expect(response).toHaveStatus(200);

    Check if the response has a specific header.

    let response = new Response("Hello World!", {
    headers: {
    "x-custom-header": "value",
    },
    });

    expect(response).toHaveHeader("x-custom-header", "value");

    Check if the response has a specific cookie.

    let response = new Response("Hello World!", {
    headers: {
    "Set-Cookie": "name=value; Path=/",
    },
    });

    expect(response).toHaveCookies(["name=value; Path=/"]);

    Check if the response has a specific status text.

    let response = new Response("Hello World!");

    expect(response).toHaveStatusText("OK");

    Check if the response has a specific status text according to the HTTP specification. (uses node:http)

    let response = new Response("Hello World!", {
    status: 400,
    statusText: "nah",
    });

    expect(response).toHaveStrictStatusText("OK"); // fails

    Check if the response matches another response.

    let response = new Response("Hello World!");

    expect(response).toMatchResponse(response);
    expect(response).toMatchResponse({ status: 200, statusText: "OK" });

    Check if the response has a specific text body.

    let response = new Response("Hello World!");

    expect(response).toHaveTextBody("Hello World!");

    Check if the response has a specific JSON body.

    let response = new Response(JSON.stringify({ foo: "bar" }));

    expect(response).toHaveJsonBody({ foo: "bar" });

    Check if a function throws a Response

    function throwResponse() {
    throw new Response("Hello World!");
    }

    expect(() => throwResponse()).toThrowResponse(new Response("Hello World!"));

    Modules

    client
    index
    matchers