Node JS - Node js Assertion Testing - Node - Node JS tutorial - webnode




What is Assertion Testing in Node.js?

  • The Node.js Assert is the most elementary way to write tests.It provides no feedback when running your test unless one fails.The assert module provides a simple set of assertion tests that can be used to test in variants.
  • The module is intended for internal use by Node.js, but can be used in application code via require ('assert').
  • However, assert is not a testing framework and cannot be used as general purpose assertion library.
Related nodejs article tags - node js - node js tutorial - node js examples

Node.js Assert Example:

Let's see a simple example of Node.js Assert.

Node JS Tutorial File: assert_example1.js

var assert = require('assert');  
function add (a, b) {  
  return a + b;  
}  
var expected = add(1,2);  
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.

 file creation command in node.js assertion

Learn Node js - node js Tutorial - file creation command in node.js assertion - node - Node js Examples

Node JS Tutorial File: assert_example2.js

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

Now you will see the Assertion Error .

Output:

 errors shown in node.js assertion

Learn Node js - node js Tutorial - errors shown in node.js assertion - node - Node js Examples


This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js Assertion Testing