简体   繁体   English

TypeError:“未定义”不是对象(正在评估“ promise.data.map”)

[英]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 尝试在controllerrootScope值之后定义rootScope ,这可能会修复错误消息

Hope this solution may help you a bit. 希望此解决方案可以对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [未处理的承诺拒绝:类型错误:未定义不是对象(评估“response.data”)] - [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'response.data')] 未处理的 Promise 拒绝:类型错误:未定义不是 object(正在评估“data.date”) - Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'data.date') React Native:TypeError:undefined 不是一个对象(评估'_this.props.data.map') - React Native: TypeError: undefined is not an object (evaluating '_this.props.data.map') [未处理的 promise 拒绝:TypeError: undefined is not an object(评估'this.state.result.map')] - [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'this.state.result.map')] undefined不是对象(评估Promise .then) - undefined is not an object (evaluating Promise .then) 谷歌地图地理编码 API 错误 [未处理的 promise 拒绝:TypeError:undefined 不是 object(评估 'data.results[0].geometry')] - Google maps Geocoding API error [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'data.results[0].geometry')] [未处理的承诺拒绝:类型错误:未定义不是对象(评估'_ref.about')] - [Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ref.about')] 可能未处理的承诺拒绝(Id:0):TypeError:undefined不是对象(评估'err.response.data') - Possible Unhandled Promise Rejection (Id: 0): TypeError: undefined is not an object (evaluating 'err.response.data') TypeError: undefined is not an object(评估'_this.state.data) - TypeError: undefined is not an object (evaluating '_this.state.data) 未处理的 promise 拒绝:TypeError: undefined is not an object(评估 '_context.t0.data.error')在 expo - Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_context.t0.data.error') in expo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM