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 an assertion that checks how much a value has changed. #330

Closed
oveddan opened this issue Dec 27, 2014 · 5 comments
Closed

Add an assertion that checks how much a value has changed. #330

oveddan opened this issue Dec 27, 2014 · 5 comments

Comments

@oveddan
Copy link

oveddan commented Dec 27, 2014

This would be used to check if, when something is invoked, something else is changed by x.

For example:

var someArray = [1, 2, 3];

expect(function(){
  someArray.pop();
}).to.change(someArray, 'length').by(-1);

I'd be glad to take a stab at this.

@keithamus
Copy link
Member

Hey again @oveddan! Thanks for the issue!

Could you explain a little further, maybe with more examples, why this should be added? In your example, I don't see why I would do that, when I could just do:

var someArray = [1, 2, 3];
someArray.pop();
expect(someArray.length).to.eql(2);

@cmpolis
Copy link
Contributor

cmpolis commented Dec 28, 2014

👍 I had been wanting this for a while and was surprised it's not part of the lib... pull request: #333

change and not.change are nice because you don't need to know or save the initial state:

var car = new Car(...);

car.accelerate.should.change(car, 'speed');
car.accelerate.should.increase(car, 'speed');

car.fillGasTank.should.not.change(car, 'oil');
car.addGallonOfGas.should.change(car, 'gas').by(1);

@keithamus
Copy link
Member

Alright, I'm sold on it. @cmpolis thanks for the PR! See #333 for continued discussion.

@oveddan
Copy link
Author

oveddan commented Dec 29, 2014

@cmpolis Thanks for doing this! Yeah @keithamus it is especially useful for testing operations that change the quantity of a persisted value, in particular when you don't know the original value that was changed.

keithamus added a commit that referenced this issue Jan 2, 2015
Added `change`, `increase` and `decrease` assertions with `by` chain (#330)
@lucasfcosta
Copy link
Member

This one is done.
Implemented at #333 and #621.

More discussion about this was done at #339 too.

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

No branches or pull requests

4 participants