Created
January 19, 2025 15:55
-
-
Save cefn/f01a25fb6a886453a315cfb68c9fbae5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function withMockedProperty< | |
Obj extends NonNullable<unknown>, | |
Name extends keyof Obj, | |
>(obj: Obj, name: Name, mock: Obj[Name], procedure: () => Promise<T>) { | |
const originalProperty = obj[name]; | |
try { | |
obj[name] = mock; | |
await procedure(); | |
} finally { | |
obj[name] = originalProperty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment