Coder Social home page Coder Social logo

Comments (13)

rwjblue avatar rwjblue commented on June 30, 2024 1

this.inject.service is only available in tests, and injects the instance of service:i18n into the test context (not the component(s) under test).

Your component would still need i18n: Ember.inject.service() in it also.

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

Use the service name only (not the type and the name):

this.inject.service('i18n')

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

I'm sorry, I actually was using this.inject.service('i18n') and filed the issue with the code after a small edit. But this.inject.service('i18n') doesn't inject it either.

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

Hmm. It should be working. Can you make a demo repo that I can use to track down the issue your are seeing?

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

@rwjblue To clarify, this.inject.service('i18n') should inject i18n into the component itself, so from the component this.get('i18n) would be the service, correct?

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

That was my problem then--a misunderstanding. I have an application injection inject i18n into all components, is there no way to inject it at test time?

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

initializers do not run in integration tests, I suppose in general you could import the initializer function and call it from your setup/beforeEach block, but that seems much less useful.

I find using foo: Ember.inject.service() in my components to be much better than attempting to globally inject things into all components for a couple reasons:

  • The previously mentioned issue with integration tests.
  • A large percentage of the time, you do not actually need all services in all components.
  • Declaring foo: Ember.inject.service() inside your component definition makes it super clear where this magical foo property is coming from.

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

I'm going to close this, as I believe we are now on the same page

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

Yep, not a bug. Thanks @rwjblue

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

For posterity, another alternative is passing in the service when you call render. E.g.

this.render(hbs{{provider-options i18n=i18n}});

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

Yep

from ember-test-helpers.

rwjblue avatar rwjblue commented on June 30, 2024

Though I personally prefer to test the actual template invocation that will be used.

from ember-test-helpers.

devinus avatar devinus commented on June 30, 2024

Yeah, I think I prefer just injecting it manually. I'm all for self-documenting code, and doing this in 1 line versus 2 in every test is a no brainer.

from ember-test-helpers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.