错误业力“未定义”范围变量在之前每个
Error Karma 'undefined' scope variable in beforeEach
这是我的 2 个文件和错误。我正在运行业力,这是我的业力.js:https://gist.github.com/devanp92/a87c0bcc2bf5b8e17f64。运行"业力开始"后,我收到此错误。这是一个非常简单的测试文件(或者我是这么假设的),我仍然收到这些错误。
主.js - 这是一个控制器
angular.module('SSLApp').controller('MainCtrl',
function($scope, $rootScope) {
$scope.thing = 1;
});
MainSpec.js - 这是我的测试文件
describe('MainCtrl', function() {
var controller, scope;
beforeEach(angular.module('SSLApp'));
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
controller = $controller('MainCtrl', {
$scope: scope
});
}));
it('should have scope to be defined', function(scope) {
expect(scope).toBeDefined();
});
});
错误!看起来它在变量中被称为未定义 MainCtrl = $controller...
TypeError: 'undefined' is not a function (evaluating 'queueableFn.fn.call(self.userContext)')
at /Users/BLAH/Documents/node_modules/karma-jasmine/lib/adapter.js:184
at `http://localhost:9876/karma.js:185`
at `http://localhost:9876/context.html:53`
Error: [ng:areq] Argument 'MainCtrl' is not a function, got undefined
http://errors.angularjs.org/1.3.8/ng/areq?p0=MainCtrl&p1=not%20a%20function%2C%20got%20undefined
at assertArg (/Users/BLAH/Documents/node_modules/angular/angular.js:1577)
at assertArgFn (/Users/BLAH/Documents/node_modules/angular/angular.js:1588)
at /Users/BLAH/Documents/node_modules/angular/angular.js:8418
at /Users/BLAH/Documents/test/controllers/MainSpec.js:9
at invoke (/Users/BLAH/Documents/node_modules/angular/angular.js:4182)
at workFn (/Users/BLAH/Documents/node_modules/angular-mocks/angular-mocks.js:2350)
at /Users/BLAH/Documents/node_modules/karma-jasmine/lib/adapter.js:184
at http://localhost:9876/karma.js:185
at http://localhost:9876/context.html:53
undefined
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
PhantomJS 1.9.8 (Mac OS X): Executed 1 of 1 (1 FAILED) ERROR (4.999 secs / 5.012 secs)
测试代码中有两个错误。
首先你使用了错误的模块功能。angular.module() 函数提供了一个真正的框架模块,而Simple module() 是 angular.mock.module() 的别名,你应该在测试中使用它。所以你应该把你的 beforeEach 函数写成如下:
beforeEach(module('SSLApp'));
此外,您使用参数定义了测试用例函数,但它应该是无参数的。可以从外部作用域访问 scope
变量。
it('should have scope to be defined', function() {
expect(scope).toBeDefined();
});
相关文章:
- Socket.IO未定义变量
- 更改 Javascript 对象中所有未定义变量的值
- coffeescript,类未定义变量
- 使用下划线未定义变量时发生抛出/捕获错误
- 网络浏览器正在成为“;严格的“;用于Javascript中未定义变量的操作
- 使用window.location时未定义变量
- 传递给数据的未定义变量
- bizzare未定义变量
- JavaScript 中全局范围内存在未定义变量的原因是什么?
- JavaScript onClick 参数表示未定义变量
- 在指令中使用 $scope.$watch 处理未定义变量的替代方法
- 对于循环错误:未捕获的引用错误,未定义变量.怎么了
- JavaScript / YouTube API - 未定义变量 YT
- 未捕获的引用错误:在测试真实性时未定义变量
- 通过使用JavaScript“未定义”(变量),我们可以释放系统内存
- 与未定义变量相关的错误
- Angularjs 控制器中的未定义变量
- 角度解析:未定义变量
- BackboneJS Uncaught ReferenceError:未定义变量
- 使用Underscore JS部分和for循环的未定义变量对象