[英]TypeScript AngularJS controller test issue with angular.mock.inject under Karma + Jasmine
I am trying to test an AngularJS 1 controller written in TypeScript with Jasmine + Karma. 我正在尝试使用Jasmine + Karma测试用TypeScript编写的AngularJS 1控制器。 But I keep hitting an error I dont know how to fix.
但是我一直遇到错误,但我不知道如何解决。 The error is quite nondescript:
该错误非常难以描述:
PhantomJS 2.1.1 (Windows 8 0.0.0) Login Controller should have text" FAILED forEach@/bower_components/angular/angular.js:341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector@/bower_components/angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 forEach@/bower_components/angular/angular.js:341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector@/bower_components/angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.019 secs / 0.015 secs)
PhantomJS 2.1.1(Windows 8 0.0.0)登录控制器应具有文本“ FAILED forEach@/bower_components/angular/angular.js:341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector @ / bower_components /angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 forEach@/bower_components/angular/angular.js :341:24 loadModules@/bower_components/angular/angular.js:4456:12 createInjector@/bower_components/angular/angular.js:4381:22 workFn@/bower_components/angular-mocks/angular-mocks.js:2507:60 /bower_components/angular/angular.js:4496:53 PhantomJS 2.1.1(Windows 8 0.0.0):执行1之1(1失败)错误(0.019秒/0.015秒)
Here is my code, notice that it doesn't really do anything. 这是我的代码,请注意它实际上并没有执行任何操作。 It seems to fail on the
angular.mocks.inject
method as when I comment this out and add some very basic tests it works. 当我将其注释掉并添加一些非常基本的测试时,在
angular.mocks.inject
方法上似乎失败了。
describe("Login Controller", () => {
var controller: App.Login.LoginController;
beforeEach(angular.mock.module("app.pages.auth.login"));
beforeEach(angular.mock.module($provide => {
$provide.value("$window", {});
}));
// I can get to here ok but this line below fails with the error above
// Note I have also tried putting $rootScope back in but to no avail
beforeEach(angular.mock.inject((/*$rootScope, $state, $http, $mdToast, $window, $log*/) => {
console.log("test");
}));
I have checked and I definitely include angular-mocks.js
in my file list (albet near the end of my dependency list). 我已经检查过,并且我肯定在我的文件列表中添加了
angular-mocks.js
(通常在依赖列表的末尾)。 If it makes any difference im using wiredep
to calculate my dependencies. 如果有什么不同,即时通讯使用
wiredep
计算我的依赖关系。
I just had the same error and in the end I managed to fix it by importing the .ts file that creates the module at the top of my test.ts file. 我只是遇到了同样的错误,最后我设法通过导入.ts文件来修复它,该文件在test.ts文件的顶部创建了模块。 You're getting this error because the .ts file that defines the "app.pages.auth.login" module isn't imported.
您收到此错误消息是因为未导入定义“ app.pages.auth.login”模块的.ts文件。
(And yes that error message is no help at all when solving this.) (是的,解决此错误消息完全没有帮助。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.