-
-
Notifications
You must be signed in to change notification settings - Fork 696
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
expect(inList).to.be.oneOf
assertion
#534
Merged
Merged
Changes from 2 commits
Commits
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
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 |
---|---|---|
|
@@ -713,7 +713,7 @@ describe('assert', function () { | |
assert.closeTo(1.5, 1.0, true); | ||
}, "the arguments to closeTo or approximately must be numbers"); | ||
}); | ||
|
||
it('approximately', function(){ | ||
assert.approximately(1.5, 1.0, 0.5); | ||
assert.approximately(10, 20, 20); | ||
|
@@ -768,6 +768,31 @@ describe('assert', function () { | |
}, 'expected [ 1, 54 ] to have the same members as [ 6, 1, 54 ]'); | ||
}); | ||
|
||
it('oneOf', function() { | ||
assert.oneOf(1, [1, 2, 3]); | ||
|
||
err(function() { | ||
assert.oneOf([1], []); | ||
}, 'expected [ 1 ] not to be an array'); | ||
|
||
err(function() { | ||
assert.oneOf({a: 1}, []); | ||
}, 'expected { a: 1 } not to be an object'); | ||
|
||
err(function() { | ||
assert.oneOf(1, 1); | ||
}, 'expected 1 to be an array'); | ||
|
||
err(function() { | ||
assert.oneOf(1, {a: 1}); | ||
}, 'expected { a: 1 } to be an array'); | ||
|
||
err(function() { | ||
assert.oneOf(9, [1, 2, 3], 'Message'); | ||
}, 'Message: expected 9 to be in [ 1, 2, 3 ]'); | ||
|
||
}); | ||
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. This is a really nice comprehensive set of tests. Thanks for this. |
||
|
||
it('above', function() { | ||
assert.isAbove(5, 2, '5 should be above 2'); | ||
|
||
|
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
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.
I wonder if this requirement really matters? Would it be so wrong to have
oneOf
work with object or arrays? Referential equality would be fine for an initial implementation - we can add.deep.oneOf()
later if we need to.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.
I could probably get that in there. Just so you know, it'll act like Python's
in
keyword. Meaning:In other words, unless I'm matching something from the first level all the way to the end of that first level object-type, it'll fail. That's the simplest way I can think to handle object-types inside of a list without a
deep
flag.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.
Without the restrictions, and without deep, I'd expect the following:
The above is fine and completely expected and acceptable piece of JavaScript. We can add
.deep
later to do more interesting things, but there's not reason to stop people doing the above.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.
Ok I'll do that. I was using
_.isEqual
(which is like==
for objects in lodash), but now I will use strict referencing via===
.