Fix mockResolvedValue not working with mocked objects

This commit is contained in:
Koen Vlaswinkel
2023-02-27 11:45:32 +01:00
parent fd2b91d4d4
commit 65e652b5e4

View File

@@ -30,6 +30,13 @@ export function mockedObject<T extends object>(
if (dynamicProperties && prop in dynamicProperties) {
return (dynamicProperties as any)[prop]();
}
// The `then` method is accessed by `Promise.resolve` to check if the object is a thenable.
// We don't want to throw an error when this happens.
if (prop === "then") {
return undefined;
}
throw new Error(`Method ${String(prop)} not mocked`);
},
});