home PYTHONJAVA
 

Node.js Assertion Testing


The Node.js Assert is the most elementary way to write tests. It provides no feedback when running your test except if one comes up fails. The assert module provides a simple arrangement of declaration tests that can be utilized to test invariants. The module is expected for inside use by Node.js, yet can be utilized in application code by means of require ('assert').

However attest isn't a trying system and can't be utilized as broadly useful attestation library.

Node.js Assert Example

Let's see a basic case of Node.js Assert.

File: assert_example1.js

  1. var assert = require('assert');  
  2. function add (a, b) {  
  3.   return a + b;  
  4. }  
  5. var expected = add(1,2);  
  6. assert( expected === 3'one plus two is three');  

It will not provide any output because the case is true. If you want to see output, you need to make the test fail.

Node.js assert example 1

File: assert_example2.js

  1. var assert = require('assert');  
  2. function add (a, b) {  
  3.   return a + b;  
  4. }  
  5. var expected = add(1,2);  
  6. assert( expected === 4'one plus two is three');  
Node.js assert example 2





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.