-
Notifications
You must be signed in to change notification settings - Fork 29
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
Implemented spy.returns method #35
Conversation
stalniy
commented
Jul 26, 2015
While I love the idea of having a server.isAvailable = chai.spy().returns(true);
// or
chai.spy.on(server, 'isAvailable').returns(true);
expect(server.isAvailable()).to.be.true;
server.isAvailable.returns(false);
expect(server.isAvailable()).to.be.false; |
@keithamus I don't like the idea of mutating inner implementation of spy function. If you want to return server.isAvailable = chai.spy.returns(true);
expect(server.isAvailable()).to.be.true;
server.isAvailable = chai.spy.returns(false);
expect(server.isAvailable()).to.be.false; * EDIT* |
@stalniy a spy is already mutable, that precedent has been set. The spy isn't just a function, it has a prototype, it has I'm quite comfortable adding Thoughts? |
@keithamus I have been thinking about this for a while, for example jasmine has var spy = spy(function() {
// some complex logic
return 1;
});
expect(spy() + 1).to.equal(2);
spy.returns(2); // why would somebody overrides my complex logic (single responsibility!)?
expect(spy() + 1).to.equal(3);
spy.returns(3);
expect(spy() + 1).to.equal(4); People will put in the code too much resetting logic and complexity will grow. I disagree with jasmine style of
And again if you want to change method implementation no need to use I haven't worked with P.S.: I disagree with having EDIT: the only issue which I currently see with using direct assignment on objects method is that then in |
any resolution on this? this would be a great feature to have |
Implemented spy.returns method
@stalniy you make some good points. I've merged this for now - because I think this is a pretty safe starting point. It'd be nice to get a good roadmap in place for chai-spies - to properly bikeshed out what we do in situations like these; formulate a kind of "design policy" if you will. |