Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

Let's rerun mocha. This should again fail, because we haven't added a method to our


module. So, let's go ahead and do that. In add.js, let's add the following code:


var addUtility = {}

addUtility.sum = function () {
'use strict';
return true;
}

module.exports = addUtility;

Let's rerun mocha. The spec should pass now:


Now, let's add the functional part to the sum method. In add_spec.js, add the following


code:


var assert = require("assert")
var addUtility = require("./../add.js");

describe('Add', function(){
describe('addUtility', function(){
it('should have a sum method', function(){
assert.equal(typeof addUtility, 'object');
assert.equal(typeof addUtility.sum, 'function');
})

it('addUtility.sum(5, 4) should return 9', function(){
assert.deepEqual(addUtility.sum(5, 4), 9)
Free download pdf