Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
test(test-support): ✅ test unknown resource type creation in fake()
Browse files Browse the repository at this point in the history
This originally came out of some code formatting causing a decrease in
code coverage. Rather than bypass the nuissance, I decided to find some
lines that were missed and test them. I discovered however that jest's
coverage report (at least for `test-support`) shows the wrong line
numbers. This appears to be an issue with `esbuild-jest`[0] so I suspect
other packages will need their Jest configs updated as well even though
the use case is pretty small.

[0]: aelbore/esbuild-jest#79
  • Loading branch information
opiation committed Apr 3, 2023
1 parent e3c0961 commit 64ccb64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/test-support/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/** @type {import('esbuild-jest').Options} */
const esbuildOptions = {
// Setting `sourcemap` to `true` is needed[0] to correctly report line numbers
// in Jest's built-in coverage reporting.
//
// [0]: https://github.com/aelbore/esbuild-jest/issues/79
sourcemap: true,
};

/** @type {import('jest').Config} */
const config = {
transform: {
"^.+\\.tsx?$": "esbuild-jest",
"^.+\\.tsx?$": ["esbuild-jest", esbuildOptions],
},
};

Expand Down
10 changes: 10 additions & 0 deletions packages/test-support/r4b/fakes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { DomainResource } from "fhir/r4";
import { fake } from "./fakes";

describe("fakes", () => {
it("throws an `Error` when attempting to generate an unrecognized resource type", () => {
const unrecognizedResourceTypeName = `BonfhirSpringTestExampleStructThingy`;

const generatingAnUnknownResourceType = () =>
// @ts-expect-error as this explicitly tests using an invalid type
fake(unrecognizedResourceTypeName);

expect(generatingAnUnknownResourceType).toThrowError(Error);
});

it.each(DomainResourceTypes)("generate fakes for %s", (resourceType) => {
const resource = fake(resourceType as ResourceType);
expect((resource as DomainResource).text?.div).not.toBeFalsy();
Expand Down

0 comments on commit 64ccb64

Please sign in to comment.