[英]TypeError: 'undefined' is not an object (evaluating 'promise.data.map')
I'm currently creating unit tests for a project implemented in angular ver. 我目前正在为以角度版本实施的项目创建单元测试。 1.2
1.2
I've created a mockService returning a deferred promise to use with my controller tests. 我创建了一个模拟服务,它返回了与控制器测试一起使用的延迟承诺。 A service method looks like this:
服务方法如下所示:
function getItems() {
var deferred = $q.defer();
deferred.resolve(["item1", "item2"]);
$rootScope.$apply();
return deferred.promise;
}
When I call this service method and deferred.resolve is executed I get an error 当我调用此服务方法并执行deferred.resolve时,出现错误
TypeError: 'undefined' is not an object (evaluating 'promise.data.map')
Does anyone know what the promise.data.map
is and what I need to do to fix the error? 有谁知道
promise.data.map
是什么以及我需要做什么来纠正错误?
Here is the solution to your problem 这是您的问题的解决方案
In your question you are trying to call the promise
before the value of the rootScope
that have been defined in your controller which is causing the problem. 在你的问题你试图调用
promise
的前值rootScope
已经在你的控制器,这是造成问题的定义。 Hence it is returning the undefined value. 因此,它将返回未定义的值。
Try to define the promise after the rootScope
values in your controller
,which may fix the error message 尝试在
controller
的rootScope
值之后定义rootScope
,这可能会修复错误消息
Hope this solution may help you a bit. 希望此解决方案可以对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.