diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ea500..7f6df06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ # Upcoming +- Expose `Queries` type + # v0.5.0 Date: 2024-05-30T13:15:37.382Z diff --git a/index.d.ts b/index.d.ts index 0674165..072f6fe 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1 +1 @@ -export { QueryDefinition, QueryBin } from "./src/QueryBin"; +export { QueryDefinition, QueryBin, Queries } from "./src/QueryBin"; diff --git a/src/example.test.ts b/src/example.test.ts index 8a60b71..10052f5 100644 --- a/src/example.test.ts +++ b/src/example.test.ts @@ -1,4 +1,4 @@ -import { QueryBin, QueryDefinition } from ".."; +import { Queries, QueryBin } from ".."; import { describe, expect, it } from "vitest"; type Method = "GET" | "PUT" | "POST" | "PATCH" | "DELETE"; @@ -9,18 +9,20 @@ interface Request { body?: Record; } -function byMethodAndUrl(method: Method, url: string): QueryDefinition { - return { - test: (item) => item.method === method && item.url.includes(url), - noneFoundMessage: `Could not find requests with method ${method} and URL containing ${url}.`, - multipleFoundMessage: `Multiple requests found method ${method} and URL containing ${url}.`, - // optional - serializeForErrorMessage: (item) => JSON.stringify(item, null, 2), - }; -} - -// This might be something -const requests = new QueryBin({ byMethodAndUrl }); +const queries = { + byMethodAndUrl: function (method: Method, url: string) { + return { + test: (item) => item.method === method && item.url.includes(url), + noneFoundMessage: `Could not find requests with method ${method} and URL containing ${url}.`, + multipleFoundMessage: `Multiple requests found method ${method} and URL containing ${url}.`, + // optional + serializeForErrorMessage: (item) => JSON.stringify(item, null, 2), + }; + }, + // This typing should be improved. Consider this interface unstable... +} as const satisfies Queries; + +const requests = new QueryBin(queries); // Let's assume we have a component under test here. describe("The Login component", () => {