Skip to content

Instantly share code, notes, and snippets.

@vasylnahuliak
Last active June 23, 2023 05:42
Show Gist options
  • Save vasylnahuliak/5d19144d348b934064fa657615413d08 to your computer and use it in GitHub Desktop.
Save vasylnahuliak/5d19144d348b934064fa657615413d08 to your computer and use it in GitHub Desktop.
Generating unique testID
type GetTestIDArgs<TestID> = {
testID: TestID;
prefix: string;
}
export const getTestID = <TestID extends Record<string, string>>({
testID,
prefix,
}: GetTestIDArgs<TestID>): TestID => {
return new Proxy(testID, {
get: (obj, prop: string) => {
return prefix ? `${prefix}_${obj[prop]}` : obj[prop];
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment