Skip to content

Instantly share code, notes, and snippets.

@amarjandu
Created April 23, 2024 00:40
Show Gist options
  • Save amarjandu/4aa9571507baa4640859651c3335b5b7 to your computer and use it in GitHub Desktop.
Save amarjandu/4aa9571507baa4640859651c3335b5b7 to your computer and use it in GitHub Desktop.
/*
* 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