Skip to content

Commit

Permalink
feat(commons): Add expectStatus jest testing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Fritze committed Mar 8, 2024
1 parent 48692f2 commit f6a3e63
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -67,6 +71,9 @@
"@mittwald/react-use-promise": "^2.1.0"
},
"peerDependenciesMeta": {
"@jest/globals": {
"optional": true
},
"@mittwald/react-use-promise": {
"optional": true
}
Expand Down
13 changes: 13 additions & 0 deletions packages/commons/src/testing/expectStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from "@jest/globals";
import assertStatus from "../types/assertStatus.js";
import { Response } from "../types/Response.js";

export function expectStatus<T extends Response, S extends T["status"]>(
response: T,
status: S,
): asserts response is T & { status: S } {
expect(response.status).toBe(status);
assertStatus(response, status);
}

export default expectStatus;
1 change: 1 addition & 0 deletions packages/commons/src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./expectStatus.js";
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6a3e63

Please sign in to comment.