Concept Flow - Assert module for assertions
Start Test
Call assert function
Check condition
Continue
End Test
The assert module checks if a condition is true. If true, the test continues. If false, it throws an error and stops the test.
import assert from 'assert'; assert.strictEqual(2 + 2, 4); assert.strictEqual('hello'.length, 5); assert.strictEqual(true, false);
| Step | Assertion | Condition Checked | Result | Action |
|---|---|---|---|---|
| 1 | assert.strictEqual(2 + 2, 4) | 2 + 2 === 4 | True | Continue |
| 2 | assert.strictEqual('hello'.length, 5) | 'hello'.length === 5 | True | Continue |
| 3 | assert.strictEqual(true, false) | true === false | False | Throw AssertionError and stop |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 |
|---|---|---|---|---|
| 2 + 2 | undefined | 4 | 4 | 4 |
| 'hello'.length | undefined | undefined | 5 | 5 |
| true === false | undefined | undefined | undefined | false |
Assert module checks conditions in code. Use assert.strictEqual(value1, value2) to test equality. If condition is true, code continues. If false, throws AssertionError and stops. Useful for testing expected results in Node.js.