-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
docs: improve assert docs #20313
docs: improve assert docs #20313
Conversation
This improves the error example output by reflecting the current state. It also makes sure the examples are up to date in general. `assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error.
assert.deepStrictEqual({ a: 1 }, { a: '1' }); | ||
// AssertionError: { a: 1 } deepStrictEqual { a: '1' } | ||
// because 1 !== '1' using SameValue comparison | ||
// AssertionError: Input A expected to strictly deep-equal input B: |
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 removed the ERR_ASSERTION
part in some cases because the line length would otherwise be above 80 characters.
I have some deviations from the the very first example or even strange issues on Windows 7 x64 (Node.js v10.0.0) concerning overall color handling and line breaks in the legend: Outputs + screenshots for 4 cases with the same code:
> require('assert').strict.deepEqual([1, 2, 3, 4, 5], [1, 2, 3, 4, '5']);
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual ... Lines skipped
[
1,
...
4,
- 5
+ '5'
]
>
> node.10.0.0.v8-6.6.exe e:\DOC\prg\js\node\-test\test.js
assert.js:77
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
[32m+ expected [39m [31m- actual [39m ... Lines skipped
[
1,
...
4,
[31m- [39m 5
[32m+ [39m '5'
]
at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:3:26)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)
> require('assert').strict.deepEqual([1, 2, 3, 4, 5], [1, 2, 3, 4, '5']);
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual ... Lines skipped
[
1,
...
4,
- 5
+ '5'
]
>
winpty ./node.10.0.0.v8-6.6.exe e:/DOC/prg/js/node/-test/test.js
assert.js:77
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
[32m+ expected[39m [31m- actual[39m ... Lines skipped
[
1,
...
4,
[31m-[39m 5
[32m+[39m '5'
]
at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:3:26)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3) Should we ignore this? |
@vsemozhetbyt I removed the extra line break in here to make it clear to the reader that it is still the same error message. Besides that I do not see any differences concerning the line breaks. The color handling is indeed weird though and that is a separate concern from this PR. I am going to try to look into it, but I sadly do not have a Windows to debug this at the moment. |
This comment has been minimized.
This comment has been minimized.
@vsemozhetbyt oh, I cite: |
BTW, they are not colored in the doc site: https://nodejs.org/download/nightly/v11.0.0-nightly2018042595197ed2b0/docs/api/assert.html#assert_strict_mode |
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.
With some possible nits)
doc/api/assert.md
Outdated
@@ -364,8 +388,16 @@ weakMap3.unequal = true; | |||
|
|||
assert.deepStrictEqual(weakMap1, weakMap2); | |||
// OK, because it is impossible to compare the entries | |||
|
|||
// Fail because weakMap3 has a property that weakMap1 does not contain: |
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.
Fail
-> Fails
? (Ignore if this is a noun)
doc/api/assert.md
Outdated
@@ -639,7 +665,9 @@ changes: | |||
* `value` {any} | |||
|
|||
Throws `value` if `value` is not `undefined` or `null`. This is useful when | |||
testing the `error` argument in callbacks. | |||
testing the `error` argument in callbacks. The stack trace contains all frames | |||
from the error passed to `ifError` including the potential new frames for |
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.
`ifError`
-> `ifError()`
?
doc/api/assert.md
Outdated
testing the `error` argument in callbacks. | ||
testing the `error` argument in callbacks. The stack trace contains all frames | ||
from the error passed to `ifError` including the potential new frames for | ||
`ifError` itself. See below for an example. |
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.
`ifError`
-> `ifError()`
?
doc/api/assert.md
Outdated
@@ -880,40 +921,34 @@ assert.ok(1); | |||
// OK | |||
|
|||
assert.ok(); | |||
// throws: | |||
// "AssertionError: No value argument passed to `assert.ok`. | |||
// AssertionError: No value argument passed to `assert.ok`. |
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.
`assert.ok()`
?
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.
TODO for another PR: unify parentheses in notStrictEqual
above and check other cases?
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.
LGTM with nits from @vsemozhetbyt addressed
Comments addressed. New CI https://ci.nodejs.org/job/node-test-pull-request-lite/602/ |
doc/api/assert.md
Outdated
|
||
assert.ok(false, 'it\'s false'); | ||
// throws "AssertionError: it's false" | ||
// AssertionError: it's false" |
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.
nit: remove "
doc/api/assert.md
Outdated
@@ -921,7 +921,7 @@ assert.ok(1); | |||
// OK | |||
|
|||
assert.ok(); | |||
// AssertionError: No value argument passed to `assert.ok`. | |||
// AssertionError: No value argument passed to `assert.ok()`. |
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, there's no period at the end of the error message:
> assert.ok()
AssertionError [ERR_ASSERTION]: No value argument passed to `assert.ok()`
>
Comments addressed. I also moved an example higher up, so it is more prominent. CI https://ci.nodejs.org/job/node-test-pull-request-lite/607/ |
Landed in 6554301 |
This improves the error example output by reflecting the current state. It also makes sure the examples are up to date in general. `assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error. PR-URL: nodejs#20313 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
This improves the error example output by reflecting the current state. It also makes sure the examples are up to date in general. `assert.throws` clarified the `ERR_AMBIGUOUS_ARGUMENT` error. PR-URL: #20313 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
This improves the error example output by reflecting the current
state. It also makes sure the examples are up to date in general.
assert.throws
clarified theERR_AMBIGUOUS_ARGUMENT
error.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes