-
-
Notifications
You must be signed in to change notification settings - Fork 703
Checking that argument given to expect is of the right type when using with include #503
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
Conversation
Hi @keithamus, I have a question related to this PR. I know the following is possible: expect(10).to.be.above(5).and.below(15); (I know that but is there a way we could make use of expect(10).to.be.above(5).or.below(0); There would be other nice uses of expect(myVar).to.be.a('string').or.an('array'); For that latter example, expect(myVar).to.be.a('string', 'array'); but that would be nice to have a nice |
@keithamus, although my previous question about |
Voilà @keithamus, I am done. A couple of things though:
Let me know if you have any comments :-) |
@keithamus... friendly ping? :) |
Hi sorry @astorije this was another that slipped through the next. I'm not sold on passing an array of types to expect({ foo: { bar: 1 }}).to.have.deep.property('foo.bar').and.be.a('number').and.equal(1).or.equal(2); Which of the following does the above assertion do? obj.foo.bar && typeof obj.foo.bar === 'number && (foo.bar === 1 || foo.bar === 2) obj.foo.bar && (typeof foo.bar === 'number' && foo.bar === 1) || foo.bar === 2 (obj.foo.bar && typeof foo.bar === 'number' && foo.bar === 1) || obj === 2) We could potentially have something like Case in point is, while #501 is definitely something I'd like to see Chai fix, I feel like this PR is going in the wrong direction for it. Make sense? Thoughts? |
Hey @keithamus, no worries :)
That is indeed the issue with an
I thought about a expect('foo').to.be.oneOf(function (either)
either.a('number');
either.a('boolean');
); but considering how
What do you mean by that? What is a matcher?
I don't think this PR is going in the wrong direction (surprising? :D), but let me explain myself.
I was not very happy with that at first as well, but a few things convinced me:
I could add a third bullet point to say that I really need that feature for this check to work, but that wouldn't be a fair argument :-) If you think this PR is going in the wrong direction, the best thing I can offer is to wrap this check in a helper as mentioned in my comment above. That way, whenever an alternative solution arises, we can just edit it there without breaking our API or plugins that would use that helper. Overall, what I want is to be done with this PR. I think having a non-ideal solution to improve over time is better than having no solutions until we find the one true perfect solution. Again, with my proposals we can make this work without affecting the API (despite my comment on the first list item) if that's your main concern. What do you think? |
Sorry, I should have clarified this. I mean matcher as in the same kind of device Sinon has, where they can be used as "generics" in combination with assertions. Done right I think it could give Chai a lot of additional power, but it needs a lot of thinking through and so it hasn't been on the short or medium term roadmap (per se). The way I see a matcher is that it could be interspersed with other assertions, to enable things like: This has been discussed a bit over in #324 and #97, but as I said nothing really firm yet.
I agree with those points, but I think a good generic solution as described above could fix those - so Im hesitant to add functionality until we know its the right functionality to add.
I agree with this, but with the caveat that a public API is a difficult thing to change, and so "the non-ideal solution" thats put in front of people and people start to use becomes "the solution". If we're discussing the same thing - how |
OK, a few things here, and I'll try to be concise this time, it's usually my weakness :)
So I do think having such helper, whether or not (So much for trying to be concise!) |
Hi @keithamus, friendly ping? I'd really like this one to get done... :-) |
Hey @astorije sorry for taking a while to reply. Overloading the |
…ing, in a naive way
… using include assertion
8b17de4
to
0acb2ec
Compare
Hi @keithamus, thanks for your comment, I am now done with changes. I have moved things to a util called Also, you will note that one must call the function with I have updated/added tests accordingly, and reverted the One last question: Do you think we should add support for single values ( |
Oh, forgot to (re-)mention, but once this makes it into What would be nice would be to add a docstring for that. What do you think and suggest? |
@keithamus meeeerge meeee :-) |
Checking that argument given to expect is of the right type when using with include
@astorije sorry was on holiday. All merged now, I'll cut a release soon 😄 |
No worries! |
Hmmmm... yes I guess that'd be a good idea actually. Feel free to either raise a new PR or tuck it into your next one for the other assertions. |
Relates to #501.