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

make dynamic mock callable #38

Merged
merged 2 commits into from
Jan 20, 2017
Merged

make dynamic mock callable #38

merged 2 commits into from
Jan 20, 2017

Conversation

mpodlasin
Copy link
Contributor

Hi.

I use your library in my side project and really like it so far. Great solution for mocking typed code, especially with es6 proxy mocks!
That being said I encountered small issues, so here is my proposition of fix:

Calling proxied function (dynamic mock implemented with es6 proxy to be precise) is impossible right now.
Code

const fnMock = Mock.ofType<Function>();
fnMock
   .setup(fn => fn())
   /* ... */

will thow error fn is not a function.

It turns out es6 proxy will be callable only if proxied object is callable.
It means that in your library line:

new Proxy({}, handler);

should be changed to

new Proxy(() => {}, handler);

Note that this is more general, since every function is an object - all dynamic object mocks will still work, and error about fn not being function will disappear.

Thanks in advance and have a great day!

@florinn
Copy link
Owner

florinn commented Jan 20, 2017

Great insight, I've added a few related tests. Thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants