我正在为 Angular Controller 编写 jasmine 测试规范。
在这里,我收到错误 TypeError: 'undefined' is not a constructor (evaluating 'new JdRes())
- 虽然我已经将其定义为
JdRes = jasmine.createSpy('JdRes');
Controller 中的代码段如下
function (myService, $scope, $attrs, $q, $parse) {
'use strict';
var JdRes, resource;
JdRes = myService('JdRes');
resource = new JdRes();
}
最佳答案
根据您提供的信息,我唯一可以得出的结论是 jasmine.createSpy('JdRes')
返回 undefined
。
这意味着 jasmine.createSpy
没有 return
语句,或者它试图返回值为 undefined
。您应该检查该函数是否确实有一个 return
语句,如果有,它的返回值不是 undefined
。我没有什么可以告诉你的了。
关于javascript - 类型错误 : 'undefined' is not a constructor (evaluating 'new JdRes()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23861015/