amk
June 8, 2015, 10:01pm
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' } });
None of the did*
lifecycle hooks fire, so how should I update my app?
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)
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}}')
amk
June 8, 2015, 10:33pm
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.
Do you have the same issue if you go through ember-qunit’s moduleForComponent
instead of relying on qunit’s module
?
https://github.com/rwjblue/ember-qunit#simple-example
amk
June 8, 2015, 11:58pm
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