diff --git a/.pnp.cjs b/.pnp.cjs index 56cf9473..568a5d25 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -1770,6 +1770,7 @@ const RAW_RUNTIME_STATE = ["@jest/globals", "npm:29.7.0"],\ ["@mittwald/react-use-promise", "virtual:e06e30328889a833dfcbfbc5c33f5e1173628bc1414934ce897e2f1b90b91087fa3f8b59a8a3ced3a53b1f7df474adc821437919c179e8897ac6cecf6bf31f00#npm:2.3.12"],\ ["@types/jest", "npm:29.5.12"],\ + ["@types/jest__globals", null],\ ["@types/mittwald__react-use-promise", null],\ ["@types/parse-path", "npm:7.0.3"],\ ["@typescript-eslint/eslint-plugin", "virtual:36a01d8083315b8a6e8362097258ea8bc0f9dfb672cb210742e054760850c673a1038f542a6b7156397b5275ace8ee0482231cac5e8898044fa1a1c29f78ee5b#npm:7.0.2"],\ @@ -1795,6 +1796,7 @@ const RAW_RUNTIME_STATE = ],\ "packagePeers": [\ "@mittwald/react-use-promise",\ + "@types/jest__globals",\ "@types/mittwald__react-use-promise"\ ],\ "linkType": "SOFT"\ @@ -1806,6 +1808,7 @@ const RAW_RUNTIME_STATE = ["@jest/globals", "npm:29.7.0"],\ ["@mittwald/react-use-promise", "virtual:c868363b9225da9941a57efe275cc186f56bbc5675507a35ee9dd42e682f6dada28f6419bfde0c8606475daefedaf411ac54fad43a935d5d29d658bdc4a86153#npm:2.3.12"],\ ["@types/jest", "npm:29.5.12"],\ + ["@types/jest__globals", null],\ ["@types/mittwald__react-use-promise", null],\ ["@types/parse-path", "npm:7.0.3"],\ ["@typescript-eslint/eslint-plugin", "virtual:36a01d8083315b8a6e8362097258ea8bc0f9dfb672cb210742e054760850c673a1038f542a6b7156397b5275ace8ee0482231cac5e8898044fa1a1c29f78ee5b#npm:7.0.2"],\ @@ -1831,6 +1834,7 @@ const RAW_RUNTIME_STATE = ],\ "packagePeers": [\ "@mittwald/react-use-promise",\ + "@types/jest__globals",\ "@types/mittwald__react-use-promise"\ ],\ "linkType": "SOFT"\ diff --git a/packages/commons/package.json b/packages/commons/package.json index cc0c4a40..859e7dcc 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -20,6 +20,10 @@ "types": "./dist/types/index.d.ts", "default": "./dist/esm/index.js" }, + "./testing": { + "types": "./dist/testing/index.d.ts", + "default": "./dist/testing/index.js" + }, "./react": { "types": "./dist/types/react/index.d.ts", "default": "./dist/esm/react/index.js" @@ -67,6 +71,9 @@ "@mittwald/react-use-promise": "^2.1.0" }, "peerDependenciesMeta": { + "@jest/globals": { + "optional": true + }, "@mittwald/react-use-promise": { "optional": true } diff --git a/packages/commons/src/testing/expectStatus.ts b/packages/commons/src/testing/expectStatus.ts new file mode 100644 index 00000000..5bbd8937 --- /dev/null +++ b/packages/commons/src/testing/expectStatus.ts @@ -0,0 +1,13 @@ +import { expect } from "@jest/globals"; +import assertStatus from "../types/assertStatus.js"; +import { Response } from "../types/Response.js"; + +export function expectStatus( + response: T, + status: S, +): asserts response is T & { status: S } { + expect(response.status).toBe(status); + assertStatus(response, status); +} + +export default expectStatus; diff --git a/packages/commons/src/testing/index.ts b/packages/commons/src/testing/index.ts new file mode 100644 index 00000000..5081dc3a --- /dev/null +++ b/packages/commons/src/testing/index.ts @@ -0,0 +1 @@ +export * from "./expectStatus.js"; diff --git a/yarn.lock b/yarn.lock index a928addd..952afcf2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1154,6 +1154,8 @@ __metadata: peerDependencies: "@mittwald/react-use-promise": ^2.1.0 peerDependenciesMeta: + "@jest/globals": + optional: true "@mittwald/react-use-promise": optional: true languageName: unknown