-
-
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
Fix 'empty' assertion called on null #763
Conversation
@shvaikalesh Good catch. However, I think this issue needs some discussion before merging a PR. Currently,
We need to decide and document what the expected behavior is for Current behavior: describe("empty", () => {
it("null", () => {
expect(null).to.be.empty; // TypeError
});
it("undefined", () => {
expect(undefined).to.be.empty; // Pass
});
it("true", () => {
expect(true).to.be.empty; // Fail
});
it("false", () => {
expect(false).to.be.empty; // Pass
});
it("0", () => {
expect(0).to.be.empty; // Pass
});
it("1", () => {
expect(1).to.be.empty; // Fail
});
it("Symbol", () => {
expect(Symbol()).to.be.empty; // Fail
});
it("function", () => {
function noop () {}
expect(noop).to.be.empty; // Fail
});
}); My first impression is that I'm not crazy about assertions like Edit: Elaborated on my opinion. |
@meeber thanks for the detailed feedback. We should definitely add tests for other data types. I agree that it is better to avoid defining library-specific meanings and let it("function", () => {
function noop () {}
expect(noop).to.be.empty; // Fail
}); In terms of the spec, functions are just objects with few additional internal methods (pretty much like promises or collections), thus this behavior does not seem very straightforward to me. What function is "empty"? Without formal parameters? With empty body? Without name or Yet another matter to decide: |
@shvaikalesh Agreed that having Yup, we had an almost identical thought process regarding the ambiguity of what it means for a function to be "chai-empty" (reminds me of "thai-spicy"). In my original unedited post, I had a separate paragraph suggesting that Not sure I agree with using default ES6 |
@shvaikalesh Thanks for your PR! 😄 I totally agree with @meeber. If I just read the docs I'd expect It also seems too dangerous to me to convert primitive types to empty arrays, because, as @meeber said before, this would make them pass the assertion and this is also something that anyone who just read the docs wouldn't expect to happen. To me, the goal of having an |
Agree with @meeber and @lucasfcosta here. We have Let's close this one for now. @shvaikalesh thank you so much for your contributions. Please don't consider this a waste of time, we'd love to see more contributions from you! If you'd like, a small refactor to this one - having it make an assertion error for |
Thanks for the feedback, |
Great idea @shvaikalesh! |
Because of
typeof null
thing andToObject
inObject.keys
,TypeError
was thrown.