impatient-js icon indicating copy to clipboard operation
impatient-js copied to clipboard

Chapter: Assertion API

Open rauschma opened this issue 6 years ago • 6 comments

rauschma avatar Jun 26 '18 16:06 rauschma

assert.equal function tests equality with == instead of ===(as mentioned in book). Reference: https://nodejs.org/api/assert.html#assert_assert_notequal_actual_expected_message

ghost avatar Jul 17 '19 01:07 ghost

Same for assert.notEqual function tests equality with != instead of !==(as mentioned in book). Reference: https://nodejs.org/api/assert.html#assert_assert_notequal_actual_expected_message

ghost avatar Jul 17 '19 01:07 ghost

Visual Studio Code marks assert.equal() as deprecated, and styles the equal as strikethrough.

This appears to be due to an older version of the @types/node module being used (12.6.2). Installing a newer version, like 14.14.21, seems to fix the issue. I did npm install @types/node from within the impatient-js-code directory.

Note: The Visual Studio Code August 2020 update added the styling of deprecated methods, which makes the @types/node bug more obvious.

mday64 avatar Jan 14 '21 22:01 mday64

assert.equal function tests equality with == instead of ===(as mentioned in book).

Note that the book and code are using the strict version. They do import { strict as assert } from 'assert';. That means that assert.equal() is actually the same as assert.strictEqual(). And that does appear to use ===.

mday64 avatar Jan 14 '21 22:01 mday64

@mday64 Thanks for reporting this! I switched to

import * as assert from 'assert/strict';

and don’t see the issue in VS Code anymore.

rauschma avatar Jan 01 '22 17:01 rauschma

@ghost:

Thanks! Originally the import statement was:

import { strict as assert } from 'assert';

To make things clearer, it is now:

import * as assert from 'assert/strict';

In the book: https://exploringjs.com/impatient-js/ch_assertion-api.html#assertions-in-software-development

rauschma avatar Jan 01 '22 17:01 rauschma