question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Injecting services for component integration tests doesn't seem to work

See original GitHub issue

The following code using this.inject.service never seems to inject the service into the component before trying to render.

/* jshint expr:true */
import { expect } from 'chai';
import {
  describeComponent,
  it
} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describeComponent(
  'provider-options',
  'Integration: ProviderOptionsComponent',
  {
    integration: true
  },
  function() {
    it('renders', function() {
      // Set any properties with this.set('myProperty', 'value');
      // Handle any actions with this.on('myAction', function(val) { ... });
      // Template block usage:
      // this.render(hbs`
      //   {{#provider-options}}
      //     template content
      //   {{/provider-options}}
      // `);

      this.inject.service('i18n'); // <= This doesn't seem to inject the i18n service
      this.render(hbs`{{provider-options}}`);
      expect(this.$()).to.have.length(1);
    });
  }
);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Nov 2, 2015

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.

0reactions
devinuscommented, Nov 2, 2015

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ember.js - Service not injected into component's integration test
So I tried to inject the service manually into the component and the test worked. This is, however, only partial solution since it...
Read more >
Integration tests in ASP.NET Core | Microsoft Learn
Integration tests confirm that two or more app components work together to produce an expected result, possibly including every component ...
Read more >
authenticateSession in integration tests? · Issue #1285 - GitHub
This component injects the session service, meaning I would like to be able to test the served content both when signed in and...
Read more >
14. Integration Testing - Spring
When the TestContext framework loads your application context, it can optionally configure instances of your test classes via Dependency Injection. This ...
Read more >
Integration Testing in Azure Functions with Dependency ...
I'm a big proponent of integration and functional tests (or “subcutaneous tests” if there's a UI). Done efficiently and sparingly, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found