我无法在我的 AngularJS 模块上进行简单的 Jasmine 测试。任何建议将不胜感激。
带控制器的模块:
(function(myApp) {
myApp.App = angular.module("MyApp", []).
config(["$routeProvider", function($routeProvider) {
$routeProvider.
when('/', { controller: "CoreAppController", templateUrl: 'App.html' }).
otherwise({ redirectTo: '/' });
}]);
myApp.App.controller("CoreAppController", function($scope, $http, widgetService) {
/* controller definition */
}
}(window.myApp = window.myApp || {}));
单元测试:
(function(myApp) {
describe("CoreAppController spec", function() {
describe("Create the CoreApp", function() {
beforeEach(angular.module("MyApp"));
describe("CoreAppController", function() {
it("Should create the core application",
expect(1).toBeGreaterThan(0)
)
});
})
});
}(window.myApp = window.myApp || {}));
测试文件中包含的文件按以下顺序排列:
- 茉莉花.js
- 茉莉花html.js
- angular.min.js
- angular.mock.js
- app.js(包含模块和控制器定义)
- CoreAppControllerSpec.js(单元测试文件)。
运行此测试会导致以下错误:
TypeError: Object # has no method 'apply' at jasmine.Queue.next_ (文件:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:1064:17) ///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2096:31) 在 jasmine.Queue.start (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2049 :8) 在 jasmine.Queue.next_ (file:///C:/TeamFoundation) 的 jasmine.Spec.execute (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2376:14) /PRE/test/jasmine/jasmine.js:2096:31) at jasmine.Queue.start (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2049:8) at jasmine.Suite .execute (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2521:14) 在 jasmine.Queue.next_ (file:///C:/TeamFoundation/PRE/test/jasmine/ jasmine.js:2096:31) 在 jasmine.Queue.start (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2049:8) 在 jasmine.Suite.execute (file:///C:/TeamFoundation/PRE/test/jasmine/jasmine.js:2521:14)
从测试中删除“模块”行会使其通过。我究竟做错了什么?