美文网首页
Mocha quick start

Mocha quick start

作者: 迈克高 | 来源:发表于2017-10-12 17:24 被阅读0次

    1.Install nodejs latest version(v8.7)

    2.Install mocha

    3.Create app js and test js files.

    //calc.js to be tested by mocha

    module.exports = function (...rest) {

    var sum = 0;

    for (let n of rest) {

    sum += n;

    }

    return sum;

    };

    //calc-test.js

    const assert = require('assert');

    const sum = require('./calc');

    describe('#calc.js', () => {

    describe('#sum()', () => {

    it('sum() should return 0', () => {

    assert.strictEqual(sum(), 0);

    });

    it('sum(1) should return 1', () => {

    assert.strictEqual(sum(1), 1);

    });

    it('sum(1, 2) should return 3', () => {

    assert.strictEqual(sum(1, 2), 3);

    });

    it('sum(1, 2, 3) should return 6', () => {

    assert.strictEqual(sum(1, 2, 3), 6);

    });

    });

    });

    4.Run the test.

    相关文章

      网友评论

          本文标题:Mocha quick start

          本文链接:https://www.haomeiwen.com/subject/lteoyxtx.html