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

Service injection in integration tests does not work #200

Closed
mydea opened this issue Oct 20, 2015 · 1 comment
Closed

Service injection in integration tests does not work #200

mydea opened this issue Oct 20, 2015 · 1 comment

Comments

@mydea
Copy link
Contributor

mydea commented Oct 20, 2015

I have a component test like this:

let userSession = Ember.Service.extends({
    language: "en",
    dateFormat: "YYYY-MM-DD",
    fullDateFormat: "YYYY-MM-DD"
});

moduleForComponent('/auction-list-item', 'Integration | Component | auction list item', {
    integration: true,

    beforeEach: function () {
        this.register('service:user-session', userSession);
        this.inject.service('user-session', { as: 'userSession' });
    }
});

test('it renders', function (assert) {
    let auction = Ember.Object.create({
      // ...
    });

    console.log(this.get("userSession.fullDateFormat"));
    this.set("myAuction", auction);

    this.render(hbs`{{auction-list-item auction=myAuction}}`); 

    //...
});

Apparently, the service is not really overwritten. The console.log outputs the correct, overwritten value, however the component itself does not seem to use the injected session. My component is basically empty (the userSession-service is injected in a initializer into all components).

I created a small repo reproducing the issue with a minimal setup:
https://github.com/mydea/ember-cli-example-app-for-github/tree/integration-test-service-injection

There I have a simple component, where I inject a service and output a simple property. In my component integration test, I overwrite the service, but the output of the component is not actually changed.

@rwjblue
Copy link
Member

rwjblue commented Oct 20, 2015

Your reproduction made tracking this down a bit easier, thank you!!

This is the same underlying issue as these:

I've got a solution that I am working on, and will close this in favor of tracking in emberjs/ember-test-helpers#108 (because the issue is ultimately upstream in ember-test-helpers).

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

2 participants