-
Notifications
You must be signed in to change notification settings - Fork 245
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
return handler in reply(...) mocks in order to allow removing handler and monitoring calls #159
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request! var handler = mock.onGet(...).reply(...).handler(); |
Hey Colin, |
What if we could have the best of both worlds and instead of returning either the instance or the handler, return a proxy that proxies the methods/properties to either the instance or the handler. A contrived example: function createProxy(instance, handler) {
var proxy = {
handler: handler,
instance: instance,
get: function() {
return instance.get.apply(instance, arguments);
}
};
Object.defineProperty(proxy, 'called', {
get: function() {
return handler.called;
},
set: function(value) {
handler.called = value;
}
});
return proxy;
} |
personally I like when things are straight forward, and the object type at hand is of clear type and interface. The suggested proxy makes it harder to follow the code and understand |
we could have a flag at the mock level determining what's the returned object... but that will create communities forking usage instead of forked code :) |
1cc8672
to
13c43f9
Compare
13c43f9
to
ce0aaf7
Compare
Similarly to WebMock it would be nice if mocking replies will return the handler so that later we can: