From c65d54349abe0bcc12e1ee3dfdd1742e86665e52 Mon Sep 17 00:00:00 2001 From: Bo Vandersteene Date: Mon, 7 Dec 2020 21:04:13 +0100 Subject: [PATCH 1/2] Create mock with values Allow the users to create a mock with default values ``` createMockWithValues(MyService, { isCreated$: new ReplaySubject(1) }) ``` --- projects/jest-utils/src/lib/create-mock.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/projects/jest-utils/src/lib/create-mock.ts b/projects/jest-utils/src/lib/create-mock.ts index 1c1dea5c..7d18f152 100644 --- a/projects/jest-utils/src/lib/create-mock.ts +++ b/projects/jest-utils/src/lib/create-mock.ts @@ -29,6 +29,19 @@ export function createMock(type: Type): Mock { return mock; } +export function createMockWithValues( + type: Type, + values: Partial>, +): Mock { + const mock = createMock(type); + + Object.entries(values).forEach(([field, value]) => { + (mock as any)[field] = value; + }); + + return mock; +} + export function provideMock(type: Type): Provider { return { provide: type, From d8b7da87157b72561469d445cf4ec552188fed47 Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Tue, 8 Dec 2020 16:19:02 +0100 Subject: [PATCH 2/2] use 2018 lib --- projects/jest-utils/tsconfig.lib.json | 2 +- projects/testing-library/tsconfig.lib.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/jest-utils/tsconfig.lib.json b/projects/jest-utils/tsconfig.lib.json index 0ef28c60..7a6179a2 100644 --- a/projects/jest-utils/tsconfig.lib.json +++ b/projects/jest-utils/tsconfig.lib.json @@ -14,7 +14,7 @@ "importHelpers": true, "allowSyntheticDefaultImports": true, "types": ["jest"], - "lib": ["dom", "es2015"] + "lib": ["dom", "es2018"] }, "angularCompilerOptions": { "enableIvy": false, diff --git a/projects/testing-library/tsconfig.lib.json b/projects/testing-library/tsconfig.lib.json index 3cac73f3..8506c888 100644 --- a/projects/testing-library/tsconfig.lib.json +++ b/projects/testing-library/tsconfig.lib.json @@ -13,7 +13,7 @@ "experimentalDecorators": true, "importHelpers": false, "types": ["node", "jest"], - "lib": ["dom", "es2015", "es2018.promise"] + "lib": ["dom", "es2018"] }, "angularCompilerOptions": { "enableIvy": false,