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

href-to causes component integration tests to fail #24

Closed
kmiyashiro opened this issue Nov 9, 2015 · 5 comments · Fixed by #27
Closed

href-to causes component integration tests to fail #24

kmiyashiro opened this issue Nov 9, 2015 · 5 comments · Fixed by #27
Assignees
Labels

Comments

@kmiyashiro
Copy link

I just tried to use href-to in my project (Ember 2.1), but it makes my component integration tests fail.

None of the namespaces return true for this line https://github.com/intercom/ember-href-to/blob/master/addon/lib/container-lookup.js#L7

TypeError: Cannot read property '__container__' of undefined
    at containerLookup (http://localhost:4002/assets/vendor.js:160928:23)
    at Object.getRouter (http://localhost:4002/assets/vendor.js:160932:12)
    at Object.hrefTo [as compute] (http://localhost:4002/assets/vendor.js:160899:35)
@g-cassie
Copy link

g-cassie commented Jan 6, 2016

Same issue here in Ember 2.0. I made the following work around:

// myapp/helpers/href-to.js
import Ember from 'ember';
import { hrefTo } from 'ember-href-to/helpers/href-to';

var application;

function getApplication() {
  var apps = Ember.Namespace.NAMESPACES.filter(function(namespace) {
    return namespace instanceof Ember.Application;
  });

  return !!apps[0] ? apps[0] : null;
}

const newHrefTo = function(params){
  if(application === undefined || !!application && application.testing) {
    application = getApplication();
  }
  return !!application ? hrefTo(params) : null;
};

export default Ember.Helper.helper(newHrefTo);

@GavinJoyce would you accept a PR along these lines?

@GavinJoyce
Copy link
Contributor

@g-cassie thanks for looking into this. Do you know why this doesn't return an app?

var apps = Ember.Namespace.NAMESPACES.filter(function(namespace) {
    return namespace instanceof Ember.Application;
  });

How many apps are in Ember.Namespace.NAMESPACES when running your tests?

@g-cassie
Copy link

g-cassie commented Jan 6, 2016

@GavinJoyce
When running develpoment version:

>>> Ember.Namespace.NAMESPACES.map(function(m){ return Ember.inspect(m)});
["Ember", "DS", "<my app name>"]

When running during a component integration test

>>> Ember.Namespace.NAMESPACES.map(function(m){ return Ember.inspect(m)});
["Ember", "DS"]

In a component integration test no app instance is created. It appears there was at one point a problem with {{link-to}} and they resolved it here. The issue is a bit different but ultimately stemming from the fact that there is no application instance in a component integration test so pieces of the container are missing.

@GavinJoyce
Copy link
Contributor

Nice one, thanks for the context. I assume this means that we can create a failing component integration test here then?

Please do create a PR, it would be a great addition to ember-href-to

@rwjblue
Copy link

rwjblue commented Jan 6, 2016

Component integration tests do not creat an application instance, so it is unlikely to be present in Ember.Namespace.NAMESPACES.

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

Successfully merging a pull request may close this issue.

4 participants