-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Added change
, increase
and decrease
assertions with by
chain (#330)
#333
Conversation
* var obj = { val: 10 }; | ||
* var fn = function() { obj.val = 10 }; | ||
* var noChangeFn = function() { return 'foo' + 'bar'; } | ||
* expect(fn).to.change(obj, 'val'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like fn
actually changes the value of val
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, good catch.
Great PR @cmpolis! Thanks for adding docs and tests! I've made a couple of comments on the code above, that I'd like to see addressed. I also have some general notes...
foo.should.change('bar', 5)
foo.should.increase('bar', 5)
foo.should.decrease('bar', 5) |
Sweet, thanks! I updated the pr w/ the notes above. As far as |
@cmpolis thanks for addressing all of my above points. PR is looking really good to me. As for the |
I am going to go with an additional argument for the change value. expect(fn).to.change(foo, 'bar', 5);
|
I think Also, using optional arguments is less flexible to enhancements and extensibility to the matcher down the line, as that argument can only be one thing.
expect(obj).to.have.property('foo')
.that.is.a('string'); And then |
Another option is instead of overloading |
You may be on to something - about
My complete personal opinion: I don't like either of these. But prefer both to adding |
foo.should.change(bar, 'val').and.be.a('number').and.be.above(5);
foo.should.change(bar, 'val').and.be.a('number').and.eql(5); This syntax would be ambiguous to me if I hadn't seen the internals: is it the change that should == 5 or Also, bar = { val: 5 };
function foo() { bar.val += 5; }
foo.should.change(bar, 'val').and.be.a('number').and.be.above(5) might as well be: bar = { val: 5 };
function foo() { bar.val += 5; }
foo();
bar.val.should.be.a('number').and.be.above(5) |
I agree with all of your points @cmpolis. Perhaps for now we agree to disagree about the |
Okay, sounds good! I'll stash If everyone is cool with |
b1fceb8
to
581cf83
Compare
messed up on b1fceb8, should be an easy fix/merge, but lmk if I should rebase my branch |
* var obj = { val: 10 }; | ||
* var fn = function() { obj.val = 15 }; | ||
* expect(fn).to.increase(obj, 'val'); | ||
* expect(fn).to.increase(obj, 'val').by(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.by
still exists in the documentation
Hey @cmpolis - I've made a couple of notes about lingering Also, I just noticed that in your commits you've removed As soon as that's done, I'll do another quick once over but it should be good to merge! At which point I'll also draw up a new issue discussing adding |
07dfb46
to
a669234
Compare
Sorry... accidentally committed before coffee 😄 Rebased and put in those changes you noted, thanks! |
LGTM 😄 |
Added `change`, `increase` and `decrease` assertions with `by` chain (#330)
Added
change
,increase
anddecrease
assertions withby
chain:I've used
change
a bunch in other testing setups and it allows for more readable and terse tests (instead ofbefore=val ... val.should.eq(before+1)
).