Skip to content

Commit

Permalink
EQA-1: Update the jest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
anjula-sack committed Jul 7, 2023
1 parent f3ddbb4 commit 62cd51b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 20 deletions.
53 changes: 33 additions & 20 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
// Sync object
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
verbose: true,
collectCoverage: true,
coverageThreshold: {
global: {
branches: 10,
functions: 10,
lines: 10,
},
},
coverageReporters: ["json-summary", "lcov"],
collectCoverageFrom: ["./src/forms/**", "!./src/components/**/*.snap"],
/**
* @returns {Promise<import('jest').Config>}
*/
module.exports = {
transform: {
"^.+\\.tsx?$": "@swc/jest",
"^.+\\.(j|t)sx?$": "@swc/jest",
},
transformIgnorePatterns: ["/node_modules/(?!@openmrs)"],
moduleNameMapper: {
"\\.(s?css)$": "identity-obj-proxy",
"@openmrs/esm-framework": "@openmrs/esm-framework/mock",
"react-i18next": "<rootDir>/__mocks__/react-i18next.js",
"lodash-es": "lodash",
"react-markdown": "<rootDir>/__mocks__/react-markdown.tsx",
"^lodash-es/(.*)$": "lodash/$1",
"^uuid$": "<rootDir>/node_modules/uuid/dist/index.js",
"^dexie$": require.resolve("dexie"),
},
collectCoverageFrom: [
"**/src/**/*.component.tsx",
"!**/node_modules/**",
"!**/vendor/**",
"!**/src/**/*.test.*",
"!**/src/declarations.d.tsx",
"!**/e2e/**",
],
coverageThreshold: {
global: {
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
},
setupFilesAfterEnv: ["<rootDir>/src/setup-tests.ts"],
testPathIgnorePatterns: [
"<rootDir>/packages/esm-form-entry-app",
"<rootDir>/e2e",
],
testEnvironment: "jsdom",
testEnvironmentOptions: {
url: "http://localhost/",
},
};

module.exports = config;
14 changes: 14 additions & 0 deletions src/components/lazy-cell/lazy-cell.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { render, waitFor } from "@testing-library/react";
import { LazyCell } from "./lazy-cell.component";

describe("LazyCell", () => {
test("renders the resolved value after the promise is resolved", async () => {
const { container } = render(
<LazyCell lazyValue={Promise.resolve("Lazy cell")} />
);
await waitFor(() =>
expect(container.firstChild).toHaveTextContent("Lazy cell")
);
});
});
25 changes: 25 additions & 0 deletions src/views/error-state/error-state.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { ErrorState } from "./error-state.component";

describe("ErrorState component", () => {
test("renders error message and header title", () => {
const error = {
response: {
status: 404,
statusText: "Not Found",
},
};
const headerTitle = "Error State";

render(<ErrorState error={error} headerTitle={headerTitle} />);

const errorMessage = screen.getByText("Error 404: Not Found");
const errorCopy = screen.getByText(
"Sorry, there was a problem displaying this information. You can try to reload this page, or contact the site administrator and quote the error code above."
);

expect(errorMessage).toBeInTheDocument();
expect(errorCopy).toBeInTheDocument();
});
});

0 comments on commit 62cd51b

Please sign in to comment.