June 2018
Intermediate to advanced
348 pages
8h 19m
English
Now, let's implement the code in the add function. We will declare a result variable into the function to house the addition between the two parameters passed to it. Open the testing.js file and apply the following changes:
const assert = require('assert');function add(n1, n2) { const result = n1 + n2; return result;}var result = add(5, 5);assert.equal(result, 10, "Should be 10");console.log("Test passed!!");
Now that we have implemented the logic for our add function, the next time we run the test, we expect that the assertion.equal function won't fail and the Test passed!! message will be displayed. Let's try it out. Execute the following command:
$ node testing.js Test passed!!
As you can see, the test passed and ...
Read now
Unlock full access