Skip to content

Commit 39796c4

Browse files
feat: create mock with values (#172)
1 parent acaa8fe commit 39796c4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

projects/jest-utils/src/lib/create-mock.ts

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ export function createMock<T>(type: Type<T>): Mock<T> {
2929
return mock;
3030
}
3131

32+
export function createMockWithValues<T, K extends keyof T>(
33+
type: Type<T>,
34+
values: Partial<Record<K, T[K]>>,
35+
): Mock<T> {
36+
const mock = createMock(type);
37+
38+
Object.entries(values).forEach(([field, value]) => {
39+
(mock as any)[field] = value;
40+
});
41+
42+
return mock;
43+
}
44+
3245
export function provideMock<T>(type: Type<T>): Provider {
3346
return {
3447
provide: type,

projects/jest-utils/tsconfig.lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"importHelpers": true,
1515
"allowSyntheticDefaultImports": true,
1616
"types": ["jest"],
17-
"lib": ["dom", "es2015"]
17+
"lib": ["dom", "es2018"]
1818
},
1919
"angularCompilerOptions": {
2020
"enableIvy": false,

projects/testing-library/tsconfig.lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"experimentalDecorators": true,
1414
"importHelpers": false,
1515
"types": ["node", "jest"],
16-
"lib": ["dom", "es2015", "es2018.promise"]
16+
"lib": ["dom", "es2018"]
1717
},
1818
"angularCompilerOptions": {
1919
"enableIvy": false,

0 commit comments

Comments
 (0)