mercredi 3 août 2016

Test the return of functions with parameters in Mocha with Chai

I wrote a basic mocha unit test to test my algorithm challenges in node. I would like an example of a mocha with chai library unit test testing the return of the function with inserted function parameters.

// algorithm.js (the function)

var alg = function(num) {
  return num;
}

module.exports = alg;

// spec/algorithm.js (the test)

var path = require('path');
var expect = require('chai').expect;

var algorithm = require(path.join(__dirname, '..', './algorithm.js'));

describe('algorithm()', function () {
  'use strict';

  it('exists', function () {
    expect(algorithm).to.be.a('function');

  });

  /*    ******* What should this be *******     */
 it('should equal 1', function () {
    expect(algorithm.alg(1)).to.equal(1);
 });
});

I used yeoman test-generator to generate the node setup. The first test to test if 'alg' is a function passes but I don't know what the second test should be after reading the documentation.

Aucun commentaire:

Enregistrer un commentaire