mwilcox
mwilcox

Reputation: 4132

Mocha: undefined is not a function

I'm running a test suite in Mocha, and I'm finding that I often get "Fatal Error: undefined is not a function", with no stack trace. The problem is usually deep in my code dependencies, and not in the test case itself. This is enormously difficult to debug.

Is there a way to turn on stack traces, or verbose errors or something? Or do I have an unusual or incorrect setup possibly?

The setup is JavaScript using require.js, running the tests in Node.

Upvotes: 0

Views: 1422

Answers (1)

Nathan Friedly
Nathan Friedly

Reputation: 8146

Requirejs returns undefined for one or more modules if it comes across a circular dependency, so that might be your issue here. Try this:

npm install -g madge
madge --circular /path/to/your/javascript

That will tell you if it found any circular dependencies. I think it only checks define() statements but that's been enough to help me track down similar issues. Here's more info on madge: https://github.com/pahen/node-madge

Upvotes: 2

Related Questions