Ember.js: ember 2.12 requires a service stubbing change in tests

Created on 16 Mar 2017  ·  3Comments  ·  Source: emberjs/ember.js

I'm getting this error with the recent update https://travis-ci.org/kellyselden/package-hint-historic-resolver/jobs/211522381#L648

Attempting to inject an unknown injection: 'service:config'

Maybe it doesn't like my service being named config? I cleared travis cache and reran master to verify it is only ember 2.12 causing this.

Most helpful comment

Alternatively, for unit tests, you can specify needs: ['service:config']. This will ensure that the service is present in the container/registry when the assertion checks for it and still allows stubbing during creation as you show above.

All 3 comments

I'm not sure this is a bug, unknown services were always supposed to throw an error. Unfortunately, this wasn't working right before, but was fixed during work on the factory for feature.

See https://github.com/emberjs/ember.js/pull/14850 for some background.

The issue was service stubbing in unit tests like this:

// with a service named `config`
let service = this.subject({
  config: {
    cacheTime: 34
  }
});

no longer works. You need to register the stub service before the subject() call now to pass the new Ember.inject.service() assertion.

Alternatively, for unit tests, you can specify needs: ['service:config']. This will ensure that the service is present in the container/registry when the assertion checks for it and still allows stubbing during creation as you show above.

Was this page helpful?
0 / 5 - 0 ratings