javascript - Node JS Mocha 测试用例未运行

标签 javascript node.js unit-testing mocha.js

我正在尝试建立一个带有测试用例的测试套件。由于某种原因,我们的射击没有任何钩子(Hook),所以我使测试用例尽可能简单。除了前面描述的那一条之外,仍然没有打印出任何 debug.log。这几乎就像代码没有看到我的任何 Mocha 测试。我在本地安装了 mocha 作为开发依赖项。它还返回许多通过的测试用例,即使我的代码中没有那么多的测试用例。我尝试卸载并重新安装 Mocha 。

终端返回 **/测试/runner.js 进入组织运行者 配置设置数据库信息:mongodb://xxxxx:xxxxxxxx@localhost/icpDB

657 次测试。 0 次失败。 268 毫秒

进程已完成,退出代码为 0

    const mocha = require('mocha');
const chai = require('chai');
const debug = require('debug');

debug.log('Entered Org Runner');
describe('Org api test suite', function () {
  before(function (done) {
    debug.log('Entered Org Before');
    done();
  });
  after(function (done) {
    debug.log('Entered Org After');
    done();
  });

  it('should create a new org', function (done) {
    debug.log('Entered Create Org It');
    done();
  });

  describe('GET Orgs', function () {
    it('should respond with an array of orgs', function (done) {
      debug.log('Entered Get Orgs It');
      done();
    });
  });

  describe('GET Org', function () {
    it('should get a org by id', function (done) {
      debug.log('It: should get a org by id');
      done();
    });

    it('should throw an error for invalid id', function (done) {
      debug.log('It: should throw an error for invalid id');
      done();
    });
  });

  describe('Update Org', function () {
    it('should update an existing org', function (done) {
      debug.log('should update an existing org');
      done();
    });
  });

  describe('Delete Org', function () {
    it('should delete an existing org', function (done) {
      debug.log('should delete an existing org');
      done();
    });
  });
});

最佳答案

事实证明问题出在我的 package.json 中使用 --recursive 。其中一个测试用例导致 Mocha 退出。当我直接将其指向上面的特定文件时,它会按预期执行。

关于javascript - Node JS Mocha 测试用例未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47483159/

相关文章:

javascript - "No ' Access-Control-Allow-Origin POST请求成功后抛出' header is present on the requested resource"错误

javascript - window.onclick 除非元素是 'someElement'

node.js - 如何在 Prisma ORM 中对数字字段使用 LIKE?

java - Eureka检测服务状态

android - 使用 Firebase 进行单元测试

javascript - 阻止插入值?

javascript - 将字符串植入 html 页面(具有挑战性)

node.js - 在 Windows 上使用构建工具升级到 Node 11.1 后的 node-sass 大小

python - 如何模拟导入实例的方法

python - 如何在 Python 中对单元测试进行时间分析?