Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Describe is not a function. when running a mocha

I have installed mocha and chai globally. Another question is how to run these two tests synchroniously in a debug mode.

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);          
      });
    });
like image 706
MANOJ Avatar asked Jan 18 '18 15:01

MANOJ


2 Answers

Just delete var describe = require ('mocha').describe;, because describe function is setup by mocha. You need to only install mocha locally and run test.

like image 79
Andrej Gajdos Avatar answered Oct 14 '22 14:10

Andrej Gajdos


Have you tried specifying the BDD argument to the mocha test runner, describe will only be availble if you specify the BDD style.

_mocha -u bdd  

If you are using VS code, it should look like this in your 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"
        }
like image 29
Paul Tierney Avatar answered Oct 14 '22 13:10

Paul Tierney