Testing new component lifecycle hooks


#1

Currently I instantiate some components programatically like:

var fooBar = app.FooBarComponent.create({ foo: 'bar' });

This is great, and easy to test because I can be sure that foo will be set to ‘bar’ on init.

However, with the new didInitAttrs hook I can’t seem to do this:

var fooBar = app.FooBarComponent.create({ attrs: { foo: 'bar' } });

  1. None of the did* lifecycle hooks fire, so how should I update my app?
  2. How do I manually make foo mutable?
    I know about the (mut) helper, but this component is not in a template
    (Yet it still has a lifecycle)

#2

This doesn’t answer your question but maybe interesting https://github.com/switchfly/ember-test-helpers/pull/38

Lets do you instantiate your component like this in your unit tests

this.render('{{my-component}}')

#3

Ok, thankyou that’s interesting for the test environment.

But I have lots of manually instantiated components in my app too which I’m now worried about.


#4

Do you have the same issue if you go through ember-qunit’s moduleForComponent instead of relying on qunit’s module?


#5

@jasonmit To clarify my issue is not so much with Testing, but rather with the fact the the hooks don’t fire unless the component is rendered. Whereas you would expect them to still have a lifecycle when constructed manually