-
Notifications
You must be signed in to change notification settings - Fork 14
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
Issue24 eachall keys #35
Open
drzaal
wants to merge
6
commits into
chaijs:master
Choose a base branch
from
drzaal:issue24-eachall-keys
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0a1298
Add EACH as a synonym to all, allow operation on objects, fix 'keys' …
drzaal b3fc462
Unit tests needed to pass. Some major changes to the expectations.
drzaal 92fb307
Fixing issues with support of chai 3.5
drzaal c1d3bca
Have to force overwrite of any and all, but might as well not impact …
drzaal 930af32
Versioning on tests, utilize skip
drzaal 87a6877
Cleaning up versioning the tests.
drzaal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,14 @@ | |
describe "using all()", -> | ||
|
||
describe "an object without length", -> | ||
nonLengthObject = {} | ||
nonLengthObject = 1 | ||
|
||
it "fails to have all elements equal to 1", -> | ||
(() -> nonLengthObject.should.all.equal 1). | ||
should.throw "expected {} to have a property 'length'" | ||
|
||
it "fails not to have all elements equal to 1", -> | ||
it "fails to have all elements equal to assertion", -> | ||
(() -> nonLengthObject.should.all.equal 1). | ||
should.throw "expected {} to have a property 'length'" | ||
|
||
should.throw "since length property unavailable: expected 1 to be an object" | ||
it "fails not to have all elements equal to assertion", -> | ||
(() -> nonLengthObject.should.not.all.equal 1). | ||
should.throw "since length property unavailable: expected 1 to be an object" | ||
|
||
describe "an object without numeric length", -> | ||
nonNumLengthObject = { length: 'a' } | ||
|
@@ -35,6 +33,15 @@ describe "an empty array's elements", -> | |
it "should trivially all not equal 1", -> | ||
emptyArray.should.all.not.equal(1) | ||
|
||
describe "an empty object's elements", -> | ||
emptyObject = {} | ||
|
||
it "should trivially all equal 1", -> | ||
emptyObject.should.all.equal(1) | ||
|
||
it "should trivially all not equal 1", -> | ||
emptyObject.should.all.not.equal(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this should fail before asserting equality on any keys. It's empty. |
||
|
||
|
||
describe "the array [1, 1]'s elements", -> | ||
array = [1, 1] | ||
|
@@ -67,6 +74,37 @@ describe "the array [1, 1]'s elements", -> | |
(() -> array.should.not.all.not.equal 2). | ||
should.throw "expected not all elements of [ 1, 1 ] to not equal 2" | ||
|
||
describe "the object {first: 1, second: 1}'s elements", -> | ||
obj = {leading: 1, trailing: 1} | ||
|
||
it "should all equal 1", -> | ||
obj.should.all.equal 1 | ||
|
||
it "should all not equal 2", -> | ||
obj.should.all.not.equal 2 | ||
|
||
it "should not all equal 2", -> | ||
obj.should.not.all.equal 2 | ||
|
||
it "should not all not equal 1", -> | ||
obj.should.not.all.not.equal 1 | ||
|
||
it "do not all equal 2", -> | ||
(() -> obj.should.all.equal 2). | ||
should.throw "expected all elements of { leading: 1, trailing: 1 } to equal 2" | ||
|
||
it "do not all *not* equal 1", -> | ||
(() -> obj.should.all.not.equal 1). | ||
should.throw "expected all elements of { leading: 1, trailing: 1 } to not equal 1" | ||
|
||
it "do not *not* all equal 1", -> | ||
(() -> obj.should.not.all.equal 1). | ||
should.throw "expected not all elements of { leading: 1, trailing: 1 } to equal 1" | ||
|
||
it "do not *not* all not equal 2", -> | ||
(() -> obj.should.not.all.not.equal 2). | ||
should.throw "expected not all elements of { leading: 1, trailing: 1 } to not equal 2" | ||
|
||
|
||
describe "the array [1, 2]'s elements", -> | ||
array = [1, 2] | ||
|
@@ -116,3 +154,4 @@ describe "the array [{ a: 'b' }, { a: 'c' }]'s elements", -> | |
it.skip "should not all have property 'a' not equal 'c'", -> | ||
(() -> array.should.all.have.property("a").not.equal("c")). | ||
should.throw "expected all elements of [ { a: 'b' }, { a: 'c' } ] to satisfy the assertion" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# This file describes the behavior of the `all` property | ||
|
||
chai_vers = process.env.npm_package_devDependencies_chai | ||
chai_major_vers = (chai_vers.split ".").shift() | ||
|
||
describe "regression testing keys()", -> | ||
console.log chai_major_vers | ||
(if chai_major_vers == '1' then describe else describe.skip) "1.4 assertion keys", -> | ||
describe "out of the box", -> | ||
obj = { first: 1, second: 2, third: 3} | ||
|
||
it "should succeed all keys, if match inclusive", -> | ||
obj.should.be.all.keys("first", "second", "third") | ||
|
||
it "should succeed all keys, fail if match subset", -> | ||
obj.should.contain.all.keys("second", "third") | ||
|
||
it "should fail not all keys, if mismatch", -> | ||
obj.should.not.have.all.keys("first", "second", "third", "fourth") | ||
|
||
it "should succeed all keys, if match subset", -> | ||
obj.should.contain.all.keys("second") | ||
|
||
it "should fail not any keys, if mismatch", -> | ||
obj.should.not.include.any.keys("fourth") | ||
|
||
describe "polyfilling any", -> | ||
ob_nested = {first: { foo: 1 }, second: { bar: 2 }, third: {}} | ||
|
||
it "should succeed some keys, if match subset", -> | ||
ob_nested.should.contain.any.keys("first") | ||
|
||
it "should succeed any keys, if match inclusive", -> | ||
ob_nested.should.not.include.any.keys("second", "third", "bar") | ||
|
||
(if chai_major_vers != '1' then describe else describe.skip) "3+ assertion keys", -> | ||
obj = { first: 1, second: 2, third: 3} | ||
|
||
it "should succeed all keys, if match inclusive", -> | ||
obj.should.be.all.keys("first", "second", "third") | ||
|
||
it "should succeed all keys, fail if match subset", -> | ||
obj.should.contain.all.keys("second", "third") | ||
|
||
it "should throw on all keys, if match subset", -> | ||
(() -> obj.should.not.be.not.all.keys("first", "second")). | ||
should.throw | ||
|
||
it "should fail on all keys, if match subset", -> | ||
obj.should.not.be.not.all.keys("fourth", "eigth", "sixteenth") | ||
|
||
it "should succeed any keys, if match inclusive", -> | ||
obj.should.include.any.keys("second", "third", "fourth") | ||
|
||
it "should fail not all keys, if mismatch", -> | ||
obj.should.not.have.all.keys("first", "second", "third", "fourth") | ||
|
||
it "should succeed some keys, if match subset", -> | ||
obj.should.contain.any.key("second") | ||
|
||
it "should succeed all keys, if match subset", -> | ||
obj.should.contain.all.keys("second") | ||
|
||
it "should fail not any keys, if mismatch", -> | ||
obj.should.not.include.any.keys("fourth") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems a bit broken. I would think that an empty object should fail at
.all
as it has no keys.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.
While I would agree...
It is currently the default behaviour, see master at test/all.coffee does:
I considered it a breaking change to modify this behaviour.
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.
Okay fair enough. We'll change this in a breaking release later on then 😄
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.
Just as a note, all should pass if the array is empty.
If it was to fail, then it's negation would have to be true. The negation of all is 'some are not', so an empty array would have to return true if some of its elements are 'not'. However, you cannot find an element in the empty set that is 'not; so it should be false; this is definitely not be behavior you want in a some statement.
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.
james, were you recommending that the some statements were not behaving as expected?
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.
No, I'm confirming that an empty array should return true if you check to see if all of its elements are equal to 1. This is logic 101.