Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to define custom mocks for same type (example, Promises) #12

Closed
uittorio opened this issue Mar 4, 2019 · 0 comments · Fixed by #125
Closed

add ability to define custom mocks for same type (example, Promises) #12

uittorio opened this issue Mar 4, 2019 · 0 comments · Fixed by #125
Assignees

Comments

@uittorio
Copy link
Member

uittorio commented Mar 4, 2019

With the current implementation of the library to mock a promise with your special promise you need to

const mockManuallyEdited = createMock<{ promise: Promise<string>; }>();
mockManuallyEdited.promise = new CustomFakePromise();
(mockManuallyEdited.promise as CustomFakePromise<string>).resolve('data');

It would be nice to have the ability to define a mock once and it will be used for that type all the time.

declare function alwaysUseCustomMock<T extends object, U extends T>(factory: () => U): <T2>(cb: (mock: T2) => T) => Extension<T2, U>;
// usage
alwaysUseCustomMock<Promise<any>, CustomFakePromise<any>>(() => new CustomFakePromise());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants