rauschma / exploring-js

20 stars 0 forks source link

Chapter: Assertion API #3

Open rauschma opened 6 years ago

ghost commented 5 years ago

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 commented 5 years ago

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

mday64 commented 3 years ago

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 commented 3 years ago

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 ===.

rauschma commented 2 years ago

@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 commented 2 years ago

@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