Skip to content

Commit

Permalink
feat: expose Queries type
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed May 30, 2024
1 parent d4050a0 commit 6d85f76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Upcoming

- Expose `Queries` type

# v0.5.0

Date: 2024-05-30T13:15:37.382Z
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { QueryDefinition, QueryBin } from "./src/QueryBin";
export { QueryDefinition, QueryBin, Queries } from "./src/QueryBin";
28 changes: 15 additions & 13 deletions src/example.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,18 +9,20 @@ interface Request {
body?: Record<string, unknown>;
}

function byMethodAndUrl(method: Method, url: string): QueryDefinition<Request> {
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<Request>({ 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<Request>;

const requests = new QueryBin<Request, typeof queries>(queries);

// Let's assume we have a component under test here.
describe("The Login component", () => {
Expand Down

0 comments on commit 6d85f76

Please sign in to comment.