From 84c44c658a6706c14f5c05c66b01ed7fbba68d0e Mon Sep 17 00:00:00 2001 From: Muhammad Zourdy Date: Fri, 1 Jul 2022 09:55:22 +0200 Subject: [PATCH] Setting up jest configs --- test/helpers/userEventSetup.ts | 13 +++++++++++++ test/setup.ts | 8 ++++++++ test/teardown.ts | 12 ++++++++++++ tsconfig.json | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/helpers/userEventSetup.ts create mode 100644 test/setup.ts create mode 100644 test/teardown.ts diff --git a/test/helpers/userEventSetup.ts b/test/helpers/userEventSetup.ts new file mode 100644 index 00000000..7c24a489 --- /dev/null +++ b/test/helpers/userEventSetup.ts @@ -0,0 +1,13 @@ +import realUserEvent from "@testing-library/user-event"; + +/** + * Setup user-event instance with custom defaults + */ +export function userEventSetup( + options: Parameters[0] = {} +): ReturnType { + return realUserEvent.setup({ + advanceTimers: jest.advanceTimersByTime, + ...options, + }); +} diff --git a/test/setup.ts b/test/setup.ts new file mode 100644 index 00000000..bf80e5fb --- /dev/null +++ b/test/setup.ts @@ -0,0 +1,8 @@ +import "@testing-library/jest-dom"; +import "whatwg-fetch"; + +import { configure } from "@testing-library/react"; + +configure({ + throwSuggestions: true, +}); diff --git a/test/teardown.ts b/test/teardown.ts new file mode 100644 index 00000000..281ca4c2 --- /dev/null +++ b/test/teardown.ts @@ -0,0 +1,12 @@ +import path from "path"; + +export default function teardown(): void { + console.log(` +================================================================================ +View Coverage Report (Open in Browser): ${path.relative( + process.cwd(), + path.join(__dirname, "../coverage/lcov-report/index.html") + )} +================================================================================ +`); +} diff --git a/tsconfig.json b/tsconfig.json index c2e44abe..aa50c7e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,6 +27,6 @@ "importsNotUsedAsValues": "preserve", "incremental": true }, - "include": ["src", "webpack"], + "include": ["src", "webpack", "test"], "exclude": ["**/node_modules", "**/.*/"] } \ No newline at end of file