This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Make controllers used with a bindToController directive easier to test #9425
Closed
Description
There doesn't seem to be a clear mechanism of unit-testing a controller that's used in a directive with bindToController: true
. These controllers assume certain properties being set before the execution of the constructor.
I could build a mechanism myself using a temporary constructor etc. but it would be nice to have something in Angular itself.
I discovered the private boolean arg later
in the $controller
service that serves the purpose:
ctrlFn = $controller(MyCtrl, {
$scope: scope,
}, true):
ctrlFn.instance.foo = "bar";
ctrl = ctrlFn();
Would you consider making that flag public and thus officially supported?
Or maybe add a helper to angular mock?
See also this Stack Overflow question.