【问题标题】:Mocha runs only one testMocha 只运行一项测试
【发布时间】:2014-08-24 15:09:28
【问题描述】:

我有一个想要用 mocha 测试的sails.js 应用程序,在我的测试文件夹中我有 2 个测试,但是当我运行 mocha 时只有一个测试被执行。

Test1.js

var request = require('supertest');

describe.only('UserController', function() {

  describe('#login()', function() {
    it('should redirect to /mypage', function (done) {
      done();
    });
  });
});

Test2.js

describe.only('UsersModel', function() {

  describe('#find()', function() {
    it('should check find function', function (done) {
      done();
    });
  });
});

我用这个命令运行测试:

./node_modules/.bin/mocha 

输出

UserController
  #login()
    ✓ should redirect to /mypage 


1 passing (10ms)

请解释一下我的错误。

【问题讨论】:

    标签: node.js unit-testing testing sails.js mocha.js


    【解决方案1】:

    这是因为您正在使用describe.only() 运行独占测试。请改用describe()

    请参阅 mocha 文档中的 exclusive tests

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 2020-08-26
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多