Initialized dependency is not present during testing

I am using ember-cli 0.0.35 and injecting a dependency on my component through an initializer. It works great in development, but there is no property when I run tests. It seems like testing calls loadInitializers, but the dependency is not displayed on this. An object ({});

I do not want to manually enter it for tests. Is there a better way to handle this?

Initializer:

var FooServiceInitializer = {
  name: 'foo',
  initialize: function (container, application) {
   application.inject('component:foo', 'foo', 'service:foo');
  }
};
export default FooServiceInitializer;

Failed test:

moduleForComponent('bar', 'Component: Bar', {
  setup: function() {
    App = startApp();
    component = this.subject({});
  },
  teardown: function () {
    Ember.run(App, App.destroy);
  }
});

test('Properties: foo', function() {
  // Make sure we injected the service
  ok(component.foo, 'foo is injected');
});
+4
source share
1 answer

As I said, it really lends itself to integration testing, since you are testing the container at this moment (and not the mini-container created by ic-ajax).

Your real test matches the lines of this

test("root lists 3 colors", function(){
  var c = App.__container__.lookup('component:foo-bar');
  ok(c.foo.blah);
});

( ), , , / api .

Ember.Test.registerHelper('containerLookup',
  function(app, look) {
    return app.__container__.lookup(look);
  }
);

App.injectTestHelpers();

test("root lists 3 colors", function(){
  var c = containerLookup('component:foo-bar');
  ok(c.foo.blah);
});

http://emberjs.jsbin.com/doxigu/edit

+2

Source: https://habr.com/ru/post/1545741/


All Articles