-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
feat: Add the assert.fail([message]) interface #1117
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
|
@@ -10,10 +10,18 @@ module.exports = function (chai, util) { | |
}; | ||
|
||
/** | ||
* ### .fail([message]) | ||
* ### .fail(actual, expected, [message], [operator]) | ||
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. Same question here regarding function signatures. |
||
* | ||
* Throw a failure. | ||
* | ||
* expect.fail(); | ||
* expect.fail("custom error message"); | ||
* expect.fail(1, 2); | ||
* expect.fail(1, 2, "custom error message"); | ||
* expect.fail(1, 2, "custom error message", ">"); | ||
* expect.fail(1, 2, undefined, ">"); | ||
* | ||
* @name fail | ||
* @param {Mixed} actual | ||
* @param {Mixed} expected | ||
|
@@ -24,6 +32,11 @@ module.exports = function (chai, util) { | |
*/ | ||
|
||
chai.expect.fail = function (actual, expected, message, operator) { | ||
if (arguments.length < 2) { | ||
message = actual; | ||
actual = undefined; | ||
} | ||
|
||
message = message || 'expect.fail()'; | ||
throw new chai.AssertionError(message, { | ||
actual: actual | ||
|
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 |
---|---|---|
|
@@ -42,10 +42,19 @@ module.exports = function (chai, util) { | |
var should = {}; | ||
|
||
/** | ||
* ### .fail([message]) | ||
* ### .fail(actual, expected, [message], [operator]) | ||
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. Same question here regarding function signatures. |
||
* | ||
* Throw a failure. | ||
* | ||
* should.fail(); | ||
* should.fail("custom error message"); | ||
* should.fail(1, 2); | ||
* should.fail(1, 2, "custom error message"); | ||
* should.fail(1, 2, "custom error message", ">"); | ||
* should.fail(1, 2, undefined, ">"); | ||
* | ||
* | ||
* @name fail | ||
* @param {Mixed} actual | ||
* @param {Mixed} expected | ||
|
@@ -56,6 +65,11 @@ module.exports = function (chai, util) { | |
*/ | ||
|
||
should.fail = function (actual, expected, message, operator) { | ||
if (arguments.length < 2) { | ||
message = actual; | ||
actual = undefined; | ||
} | ||
|
||
message = message || 'should.fail()'; | ||
throw new chai.AssertionError(message, { | ||
actual: actual | ||
|
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
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.
@chaijs/chai Anyone know how the website generation script handles listing multiple function signatures in this way? Or the proper way to do this with jsdoc in general? I struggled with this problem quite a bit in chaijs/check-error#18, and ended up including a single function signature at the top (with optional parameters) but documenting the alternate signatures in the jsdoc body. Not sure what the best approach is.
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.
There is a possible solution for handling multiple function signature used in the
assert.throws
documentation. But I'm not sure this is the proper way of doing though: as a user, this is only by looking at the example section I was able to understand the various signatures for that method.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.
FWIW, I passed the source code through
dox
(which I assume to be the jsdoc parser used for the website). Here is the relevant part of the output:As you can see, it produces two
<h3>
elements--once for each signature. Which seems quite reasonnable. Maybe we could ping someone at the chai-doc team to check if this is an issue?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.
Yup, chai-docs is using
dox
. That behavior looks promising. @astorije might know for sure.