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 'generate' of undefined

See original GitHub issue

Ember 2.9.0

Running ember test with ember-href-to v1.14.0 is fine. Using v1.15.0 we get some failing integration tests:

        actual: >
            null
        stack: >
            TypeError: Cannot read property 'generate' of undefined
                at Class.generate (http://localhost:7357/assets/vendor.js:49196:42)
                at Class.urlFor (http://localhost:7357/assets/vendor.js:76358:48)
                at hrefTo (http://localhost:7357/assets/vendor.js:144238:26)
                at Class.compute (http://localhost:7357/assets/vendor.js:144251:23)
                at Child.compute (http://localhost:7357/assets/vendor.js:34567:26)
                at Child.value (http://localhost:7357/assets/vendor.js:34897:27)
                at read (http://localhost:7357/assets/vendor.js:35290:21)
                at Object.readArray (http://localhost:7357/assets/vendor.js:35312:16)
                at Child.compute (http://localhost:7357/assets/vendor.js:34434:48)
                at Child.value (http://localhost:7357/assets/vendor.js:34897:27)
        message: >
            Died on test #1     at Module.callback (http://localhost:7357/assets/tests.js:27187:24)
                at Module.exports (http://localhost:7357/assets/vendor.js:115:32)
                at requireModule (http://localhost:7357/assets/vendor.js:36:18)
                at TestLoader.<anonymous> (http://localhost:7357/assets/test-support.js:7700:11)
                at TestLoader.require (http://localhost:7357/assets/test-support.js:7690:27)
                at TestLoader.loadModules (http://localhost:7357/assets/test-support.js:7682:16)
                at Function.load (http://localhost:7357/assets/test-support.js:7633:26): Cannot read property 'generate' of undefined
        Log: |

The test renders a component that contains a href-to call:

I haven’t manage to recreate it in tests on ember-href-to yet

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
GCheung55commented, Dec 29, 2017

Looking around some more, it looks like the integration test is setting up the router with:

beforeEach() {
  getOwner(this).lookup('router:main').setupRouter();
}

@GavinJoyce Is there a way to automatically setup the router without needing to manually add a beforeEach to every integration test?

1reaction
GCheung55commented, Dec 28, 2017

I was seeing this on 1.15.x with ember@2.17.1. Looking into this some it looks like the router isn’t setup yet, that’s why this._routerMicrolib is undefined.

this._routerMicrolib is setup in the _initRouterJs method. My guess is that the router isn’t setup in component tests.

Reference: https://github.com/emberjs/ember.js/blob/master/packages/ember-routing/lib/system/router.js#L396

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Why does Javascript generate "Uncaught TypeError: Cannot ...
Why does Javascript generate "Uncaught TypeError: Cannot read property of undefined" if this property is defined? · Subscribe to RSS.
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
Interpreting undefined or null as subtypes of all other types can lead to runtime problems. For example, if you try to get the...
Read more >
TypeError: Cannot read property 'startsWith' of undefined
TypeError : Cannot read property 'startsWith' of undefined: D:\codespace\zzz\node_modules\mongodb-connection-string-url\lib\index.js:9 return ...
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