在测试之后编写'if'语句在节点js中的mocha-chai中通过或失败

时间:2018-01-19 09:49:43

标签: node.js mocha

有没有办法在测试通过或失败后编写'if'语句?

var assert = require('chai').assert;
var expect = require('chai').expect;
var first = require('../first');
describe('First', function(){ 
  it('first should return hello world', function(){ 
    assert.equal(first(), 'hello world') 
  });
});

1 个答案:

答案 0 :(得分:0)

是的,你可以

查看Mocha - before, after, before each, after each hooks

在您的代码中,它将类似于:

describe('First', function(){ 

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

  after(function() {
     // runs after all tests in this block
  });

  it('first should return hello world', function(){ 
    assert.equal(first(), 'hello world') 

    // if you want another assertion you can add one here. for example:
    assert.notEqual(first(), 'bye world') 
  });
});