I have tricky function that I want to spy on.
$rootScope.AlertsGlobal = {};
this.updateHeight = function (clientHeight) {
$rootScope.AlertsGlobal.clientHeight = clientHeight;
};
This refers to the angular controller
var GlobalAlertsController = function() {
}
like so ...
var GlobalAlertsController = function() {
this.updateHeight = function (clientHeight) {
$rootScope.AlertsGlobal.clientHeight = clientHeight;
}
The function lives inside directives controller and is required by another controller (requires difference in unit test? ).
require: 'MainGlobalAlerts',
Inside of my unit test I mocked out my directive
html = angular.element("<my-directive> </my-directive")
element = $compile(html)($rootScope)
$rootScope.$digest(element)
scope = element.scope() // note html and scope are defined below describe
I have tried to sinon spy this updateHeight() a couple of different ways.
sinon.spy(scope, 'updateHeight')
sinon.spy($rootScope, 'updateHeight')
However my error statement
Typeerror: Attempted to wrap undefined property updateHeight as a function
Since updateHeight Is defined with this I am not sure how to call this method if I cannot spy it.
Aucun commentaire:
Enregistrer un commentaire