我有以下情况,在我的指令中,我有一个用"var method have“声明的方法。我初始化了我的测试,但是我一直收到一个错误,说这个方法不存在。为了解决这个问题,我在考试中遗漏了什么?
//my test
beforeEach(function () {
spyOn(scope, 'innerMethod'); -- fails here with method does not ae
});
//my directive
link: function (scope, elm, attrs) {
var innerMethod = function() {
//do something here
}
});编辑--我最终只是在模拟茉莉花测试中的功能。
发布于 2016-02-01 12:09:49
问题是innertMethod没有附加到指令的作用域。相反,它只存在于指令的本地范围中。
为了使您的测试能够访问innerMethod,您需要将它附加到带有scope.innerMethod = function() { ... }的指令中的作用域,然后在测试中可以从必须注入的指令引用它。
https://stackoverflow.com/questions/35027183
复制相似问题