11

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);          
      });
    });
1

2 Answers 2

11

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

Sign up to request clarification or add additional context in comments.

2 Comments

@TamusJRoyce I have no idea. I didn't try to add any breakpoints.
I didn’t leave any context, did I? Apologies. If I run the test file without using mocha tool, and requiring mocha instead, I can set a breakpoint in visual studio code or other ide and step through it. I needed to step through functional tests to test how my code works combined with someone else’s. Where unit tests don’t need this feature. Most of the time this answer is the best one. Unless you can step through mocha tests using the tool instead of node —debug?
2

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"
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.