Michael Zhang
Michael Zhang

Reputation: 1755

Run Mocha tests from Node - 'describe' is not defined

I'm trying to run Mocha tests after, for example, an event fires from within a Node program. I'm trying to avoid using child_process. After reading this wiki page, I set up my code as follows:

var Mocha = require("mocha");
var Reporter = require("./reporter");

var mocha = new Mocha({
    ui: "tdd",
    reporter: "spec"
});
mocha.addFile("test.js");

mocha.run();

Where test.js has a valid mocha test. But when I run this, I keep getting ReferenceError: describe is not defined. Why is this happening? (When I searched this problem on Google most of the solutions were about people running test.js with node rather than mocha.)

Upvotes: 1

Views: 8760

Answers (2)

PI Swathi
PI Swathi

Reputation: 1

var Mocha = require("mocha");
var Reporter = require("./reporter");

*File "<ipython-input-42-669e9b71bd81>", line 1
    var Mocha = require("mocha");
            ^
SyntaxError: invalid syntax*

as output

1.describe() is not defined as it was not availabel in H2OFrame

Upvotes: -1

chrisbajorin
chrisbajorin

Reputation: 6153

As per their docs:

The BDD interface provides describe(), context(), it(), specify(), before(), after(), beforeEach(), and afterEach().

You have ui set to "tdd":

The TDD interface provides suite(), test(), suiteSetup(), suiteTeardown(), setup(), and teardown():

Upvotes: 10

Related Questions