As much as I search Google for results in Spanish, they do not appear and I did not understand what the assert is. What role do they have in NodeJS?
That curiosity stings me first of all.
As much as I search Google for results in Spanish, they do not appear and I did not understand what the assert is. What role do they have in NodeJS?
That curiosity stings me first of all.
The assert function or module is usually used in all languages that have it to verify that the content that is being passed to the function is true and exit the program or launch an error otherwise.
In the case of NodeJS the module assert defines a series of functions (assert (), assert.deepEqual () , assert.doesNotThrow () ...) that can be used in your code to perform checks, for example assert.throws () and assert.doesNotThrow () check that the function evaluated with these parameters throws a certain exception, or not does, respectively. The different functions of this module allow you to make more or less complex checks.
When would you like to use asserts? In general, asserts are used in tests, since they allow to verify that certain conditions have been met and allow you to display personalized messages.