0
0
Node.jsframework~10 mins

Assert module for assertions in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the assert module in Node.js.

Node.js
const assert = require('[1]');
Drag options to blanks, or click blank then click option'
Aassert
Bfs
Chttp
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using other module names like 'fs' or 'http' instead of 'assert'.
Forgetting to put the module name in quotes.
2fill in blank
medium

Complete the code to assert that two values are strictly equal.

Node.js
assert.[1](5, 5);
Drag options to blanks, or click blank then click option'
AnotEqual
BdeepEqual
CstrictEqual
Dthrows
Attempts:
3 left
💡 Hint
Common Mistakes
Using notEqual which checks for inequality.
Using deepEqual which checks object structure.
3fill in blank
hard

Fix the error in the code to assert that a function throws an error.

Node.js
assert.[1](() => { throw new Error('fail'); });
Drag options to blanks, or click blank then click option'
AdoesNotThrow
Bthrows
Cok
DstrictEqual
Attempts:
3 left
💡 Hint
Common Mistakes
Using doesNotThrow which expects no error.
Using strictEqual which compares values.
4fill in blank
hard

Fill both blanks for deep equality and inequality assertions on objects.

Node.js
assert.[1]({a: 1}, {a: 1}); // deep comparison
assert.[2]({a: 1}, {a: 2}); // should pass
Drag options to blanks, or click blank then click option'
AdeepEqual
BstrictEqual
CnotDeepEqual
Dok
Attempts:
3 left
💡 Hint
Common Mistakes
Using strictEqual for objects which compares references.
Using ok which checks truthiness.
5fill in blank
hard

Fill all three blanks to assert that a value is truthy, not equal to zero, and not strictly equal to 1.

Node.js
assert.[1](value); // check truthy
assert.[2](value, 0); // check not equal
assert.[3](value, 1); // check not strictly equal
Drag options to blanks, or click blank then click option'
Aok
BnotEqual
CnotStrictEqual
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using equal instead of notEqual.
Confusing notEqual and notStrictEqual.