【问题标题】:TypeError: Describe is not a function. when running a mochaTypeError:描述不是函数。运行摩卡咖啡时
【发布时间】:2018-06-27 18:23:20
【问题描述】:

我已经在全球范围内安装了 mocha 和 chai。另一个问题是如何在调试模式下同步运行这两个测试。

var describe = require ('mocha').describe;
var it = require ('mocha').it;
var before = require ('mocha').before;
var expect = require('chai').expect;
var assert = require('chai').assert;
var API = require('C:/Users/Niku/Desktop/api/api/controllers/API.js');


describe('getResponse tests', function() {


    it('getResonse first from server and then from local', function(done) {
      var ApI = new API(Id, key, List);

      rep1 = API.getResponse();
      assert.isNotEmpty(rep1);
      console.log("1" + api_jwt);

      assert.deepEqual(rep1, KPOAuthAPI.getResponse());

    });

describe('getResponse from server after Timeout', function() {
      it('getResponse should return the rep from local', function(done) {

        var API = new API(Id, key, List);
        var rep1 = API.getResponse();
        assert.notEqual(rep, rep1);          
      });
    });

【问题讨论】:

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


【解决方案1】:

只需删除var describe = require ('mocha').describe;,因为describe功能是由mocha设置的。你只需要在本地安装 mocha 并运行测试。

【讨论】:

  • @TamusJRoyce 我不知道。我没有尝试添加任何断点。
  • 我没有留下任何上下文,是吗?道歉。如果我在不使用 mocha 工具的情况下运行测试文件,而是需要 mocha,我可以在 Visual Studio 代码或其他 IDE 中设置断点并逐步执行。我需要逐步完成功能测试,以测试我的代码如何与其他人的代码结合使用。单元测试不需要此功能。大多数时候,这个答案是最好的。除非您可以使用工具而不是 node —debug 来逐步完成 mocha 测试?
【解决方案2】:

您是否尝试过为 mocha 测试运行程序指定 BDD 参数,仅当您指定 BDD 样式时,describe 才可用。

_mocha -u bdd  

如果你使用的是 VS 代码,它在你的 launch.json 中应该是这样的

{
            "type": "node",
            "request": "launch",
            "name": "Mocha Tests",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "args": [
                "-u",
                "bdd",
                "--timeout",
                "999999",
                "--colors",
                "${workspaceFolder}/dist/tests"
            ],
            "internalConsoleOptions": "openOnSessionStart"
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2015-12-22
    • 2012-07-06
    • 1970-01-01
    相关资源
    最近更新 更多