Skip to content
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 'generate' of undefined #94

Open
brianshano opened this issue Oct 27, 2017 · 13 comments
Open

TypeError: Cannot read property 'generate' of undefined #94

brianshano opened this issue Oct 27, 2017 · 13 comments

Comments

@brianshano
Copy link

brianshano commented Oct 27, 2017

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

@mazondo
Copy link
Contributor

mazondo commented Nov 1, 2017

This is happening to us as well, dropping to 1.14 resolved it

@GavinJoyce
Copy link
Contributor

@mazondo what version of ember are you using?

@nadnoslen
Copy link

I just bumped into this in my unit tests (works fine in the app).

Essentially I have a component rendering a handful of links using href-to.

Ember-2.9.1
ember-href-to-1.15.1

Just noticed that @mazondo downgraded ember-href-to-1.14; I'll try that.

@nadnoslen
Copy link

So downgrading to ember-href-to-1.14.0 worked for me too. Thanks @mazondo

@cmgurba
Copy link

cmgurba commented Dec 4, 2017

Errors exist in Ember-2.16.2 as well.
Confirmed downgrading to ember-href-to-1.14.0 does get rid of the errors here as well.

@GCheung55
Copy link
Contributor

GCheung55 commented Dec 28, 2017

I was seeing this on 1.15.x with [email protected]. 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

@GCheung55
Copy link
Contributor

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?

@panthony
Copy link

@GCheung55 Adding this did fix this particular issue but it broke lot's of other tests.

Looks like this call has side-effects that impact other tests.

@GCheung55
Copy link
Contributor

@panthony I see. My project has a couple of components that use href-to so setting up the router in a beforeEach for their respective tests addressed the issue but I didn’t see side effects to other tests.

We’re the side-effect errors you saw consistent?

@panthony
Copy link

@GCheung55 Typically I have:

In integration tests:

Source: | Error: Must setup rendering context before attempting to interact with elements.

In route tests:

Error: Assertion Failed: Attempting to inject an unknown injection: 'service:i18n'

If I add service:i18n in needs array it will fails eventually with:

Error: Property set failed: object in path "session" could not be found or was destroyed.

Maybe this is due to ember-simple-auth somehow.

I did not try to fix them really. I do not wish to add something in a test that break another one, setupRouter do something that lives beyond the test.

@hoIIer
Copy link

hoIIer commented Mar 18, 2018

+1 just ran into this when using <a href={{href-to foo}} in integration test, going to downgrade for now

@chbonser
Copy link

Just in case this data point is helpful... I'm using Ember 3.3.1 and both 1.14.0 and 1.15.1 cause the error.

@hoIIer
Copy link

hoIIer commented Sep 22, 2018

seems like _router is undefined in urlFor which leads to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants