June 2025
Intermediate to advanced
837 pages
24h 50m
English
The name of the assert module is derived from the assertions. These are the methods provided by your testing framework to check if a value meets your expectations. First, Listing 23.2 shows a simple example of a unit test created with the means of the assert module.
import { strictEqual } from 'assert'; const myBuffer = Buffer.from('Hello World'); const result = myBuffer.toString(); strictEqual(result, 'Hello World');
Listing 23.2 Example of a Unit Test with the “assert” Module (buffer.js)
At the start of the test, you import the strictEqual function from the assert module. This type of import statement isn’t directly related to the test, but represents necessary preparatory work. The first step of the AAA test ...
Read now
Unlock full access