Reputation: 819
Say I have a deeply nested component structure and I don't want to stub the dependencies (mainly services and ajax calls) of all the child components and their child components. Is there a way to inject a stub like Ember.Component.create({})
into the container to replace the real one for that test. It seems like it should be possible but I can't seem to figure out the syntax or find it documented anywhere.
Upvotes: 2
Views: 1274
Reputation: 819
After experimenting a bit more, it turned out to be really simple:
moduleForComponent('test-component', 'Integration | Component | test', {
integration: true,
beforeEach: function () {
this.owner.register('component:test-component2', Ember.Component.extend());
}
});
Now {{test-component2}}
inside {{test-component}}
is going to be a default Ember component.
To also stub the templates add this.owner.register('template:components/test-component2', '')
in the beforeEach
callback.
💡 For Ember 2 use this.register(...)
instead of this.owner.register(...)
.
Edit: Updates (Ember 3 syntax, template stub) based on comments
Upvotes: 9