question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'setUp' of undefined

See original GitHub issue

So I’m looking at Caolan Mcmahon’s Tutorial Adding the following code causes the title error

    console.log = function (str) {
        test.equal(str, 'doubled: 24');
    };

The problem line is test.equal(str, 'doubled: 24');.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
shadowmintcommented, Jun 22, 2014

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:

  // Exact match
  {
    var query = store.query('value').only('1');
    store.collect(query).then((records) => {
      test.equals(records.length(), 2);
      test.equals(records.all()[0].value, '1');
      test.equals(records.all()[1].value, '1');
      test.done();
    });
  }

  // Upper bound
  {
    var query = store.query('value').upperBound('1');
    store.collect(query).then((records) => {
      console.log('Items?', records.all());
      test.equals(records.length(), 2);
      test.equals(records.all()[0].value, '1');
      test.equals(records.all()[1].value, '1');
      test.done(); // <--- woops! This should be a separate test...
    });
  }

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)

1reaction
terryweisscommented, May 31, 2013

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){ // code… if (someCondition){ callback(); //<- problem here, should have been return callback() } callback(); }

Then in the test:

exports.myTest(test){ A(function(){ test.done() }) }

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'setup' of undefined (line:289)
Hi everybody, I have been playing with uibuilder and really enjoying it. Developing it locally, everything has went smoothly but I have been...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError: Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an undefined...
Read more >
What is "TypeError: Cannot read property 'state' of undefined"?
The error message says that you don't have the state property on an undefined object. To decode this, we have to understand the...
Read more >
javascript - TypeError: Cannot read properties of undefined ...
In some case, your args[0] is undefined that's why it is throwing the error. Use of ? will only check for toLowerCase() when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found