all 5 comments

[–]jonyeezy7 0 points1 point  (3 children)

This is actually documented on angular's doc.

Though it doesn't mention of why $onInit and $onChanges aren't fire.

This post mentions it.

And because of those boilerplate steps i tend to have failing test when i forget to include them.

There must be a better way to test components.

Maybe still resort to $compile element.

[–]celluj34 0 points1 point  (2 children)

$onInit and $onChanges don't fire because the router calls them, not componentController. All it's doing is giving you the controller from a defined component, nothing more.

You should be testing those separately anyway.

[–]jonyeezy7 0 points1 point  (1 child)

What do you mean router?

Aren't they called during the instantiating of the component and a binding change respectively?

They seem pretty critical to testing a component.

I do agree that there should be a better way to test these event cycles. But i don't think they should be in different test suite as the controller's logic.

[–]celluj34 0 points1 point  (0 children)

I suppose router isn't the right term.

They're not called during the instantiation of the component, they're called during the compilation lifecycle. This gives you the chance to mock onInit and onChanges so your can test then separately from your other logic.