mocha 学习

mocha

  • install npm i mocha --save-dev

  • demo

    var assert = require('assert');
    describe('Array', function () {
        describe('#indexOf()', function () {
            it('should return -1 when the value is not present', function () {
                assert.equal([1, 2, 3].indexOf(4), -1);
            });
        });
    });
    
  • tips:

    • 需要创建test文件夹,而且放在和package.json同级目录下面的
    • 配置package.json的script的"test":"mocha"
    • 运行 npm test
  • hooks

describe('hooks', function () {
  before(function () {
    // runs once before the first test in this block
  });

  after(function () {
    // runs once after the last test in this block
  });

  beforeEach(function () {
    // runs before each test in this block
  });

  afterEach(function () {
    // runs after each test in this block
  });

  // test cases
});

posted @ 2020-08-12 17:02  cyany_blue  阅读(104)  评论(0编辑  收藏  举报