Created
April 23, 2024 00:40
-
-
Save amarjandu/4aa9571507baa4640859651c3335b5b7 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Enables contextual overrides to generation of mocked values, there is a constraint here is that | |
* the underlying library only allows MockeryMapper to be used on `string` values, schema's with values such as | |
* `number` or `boolean` will not be mocked with contextual values at the moment. | |
* TODO: enhance this to allow any context to be considered for any value type. | |
* */ | |
export function mockeryMapperWithContext<T extends Record<string, string>>( | |
context: T, | |
) { | |
return (keyName: string): FakerFunction | undefined => { | |
if (keyName in context) { | |
return () => context[keyName]; | |
} | |
return mockeryMapper(keyName); | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment