-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property 'setUp' of undefined #198
Comments
Ahh! ok i figured it out. Looks like Mcmahon's tutorial is old.. and node unit has been updated to change the way they define tests.. so.... you'll need to define test-doubled.js in the manner outlined on the home page of the project: More explicitly... the contents of test-doubled.js would look something like this: |
My code as followed, and give some error info: FAILURES: Undone tests (or their setups/teardowns):
To fix this, make sure all tests call test.done() /////////////////////////////////////////////////////////////////////////////////
|
I'm seeing the same issue, even after rewriting the tests in the for with the setUp and tearDown. It happens after the last unit test has run successfully. node_modules/nodeunit/bin/nodeunit test test_app test_config test_references test_v1 OK: 5 assertions (30ms) project/nodetest/node_modules/nodeunit/lib/core.js:284 |
I saw this issue today on a set of tests that had previously been working. In the event that this helps someone else, it was an issue with a badly formed callback. The error message is misleading. What I had done was something like this: function A(callback){ Then in the test: exports.myTest(test){ This issue is that test.done() was called twice due to that upstream callback being a problem. That second call to test.done() was causing nodeunit to look for a test that doesn't exist and failing on the call to "group". But it's not clear from the error what is happening. I found it by using mocha to run the same test and it correctly reported "done() called more than once" which is what I think nodeunit needs to do. t. |
I have the same problem as @Nethken The problem actually lies in the fact that nodeunit seems to use console.log for its output as well. A rough working example: var postgres = require('../postgres.js')
var events = require('events')
old_console_log = console.log
module.exports = {
setUp: function(callback){
old_console_log("in setUp")
return callback();
},
tearDown: function(callback){
console.log = old_console_log
old_console_log("in tearDown")
return callback();
},
readANumber: function(test){
var ev = new events.EventEmitter();
process.openStdin = function() { return ev; }
process.exit = test.done;
console.log = function(str){
old_console_log("Asserting: " + str)
test.equal(str, 'sumting');
}
postgres.read();
ev.emit('data', 'sumting');
}
} |
you can use console.info() or console.warn() instead of console.log() which cause the problem |
Any progress on this? |
This is a misleading error message you sometimes get when callbacks are hit multiple times or in odd ways. I'm closing this but feel free to open a new issue to improve the error message. |
For anyone else who finds this, 'when callbacks are hit multiple times or in odd ways' probably means; if you have multiple callbacks that invoke test.done() asynchronously. For example:
Will sometimes trigger it, sometimes not depending on race conditions; you can resolve by ensuring that all the promises are resolved and then calling test.done(), not calling it multiple times. (It would be very useful is test.done() error'd with a meaningful error message if it was called outside of a test scope) |
A null check is missing in the core.js file. After running nodeunit webserver/tests/ I was having the following error and I was struggling to understand what the issue was. core_auth_tokenmanager_tests /usr/local/lib/node_modules/nodeunit/lib/core.js:285 so I have added a null check to the file /usr/local/lib/node_modules/nodeunit/lib/core.js before of the line 285
And once I have run nodeunit webserver/tests/ I didn't get the exception and I got the name of the file which is throwing the exception (so I have realised that my error was caused by a file (which is not a unit test) that I have created in the same folder of the unit tests :- ) ) core_auth_tokenmanager_tests testAppConfig FAILURES: Undone tests (or their setups/teardowns): - auth - cryptoCookieKey1 |
So I'm looking at Caolan Mcmahon's Tutorial
Adding the following code causes the title error
The problem line is
test.equal(str, 'doubled: 24');
.The text was updated successfully, but these errors were encountered: