Javascript Angularjs在测试打字稿时出错,Angularjs带有茉莉花和因果报应

Javascript Angularjs在测试打字稿时出错,Angularjs带有茉莉花和因果报应,javascript,angularjs,typescript,jasmine,karma-runner,Javascript,Angularjs,Typescript,Jasmine,Karma Runner,我想用Karma和Jasmine测试我的基于AngularJS和TypeScript的应用程序 我编辑的controllerSpecs.ts: /// <reference path="../references.ts" /> describe('ConfigCtrl', () => { var configCtrl, scope; beforeEach(angular.mock.module('typewritingApp')); beforeEach(angular.

我想用Karma和Jasmine测试我的基于AngularJS和TypeScript的应用程序

我编辑的
controllerSpecs.ts

/// <reference path="../references.ts" />

describe('ConfigCtrl', () => {
var configCtrl, scope;

beforeEach(angular.mock.module('typewritingApp'));

beforeEach(angular.mock.inject(($rootScope) => {
    scope = $rootScope.$new();
    configCtrl = new App.TestCtrl(scope);
}));

it('should be true', () => {
    expect(true).toBe(true);
});
});
module App {
import TypewritingCtrl = App.TypewritingCtrl;
import MenuCtrl = App.MenuCtrl;
var typescrip: ng.IModule;
var typewritingapp: ng.IModule = angular.module("typewritingApp", ["ngRoute", "ui.bootstrap", "LocalStorageModule", "ui.event", "timer"])
    .controller("TestCtrl", ["$scope", TestCtrl])

}
/// <reference path="../references.ts" />
module App {
export class TestCtrl {
    constructor($scope: ng.IRootScopeService) {

    }
}
}
My
TestController.ts

/// <reference path="../references.ts" />

describe('ConfigCtrl', () => {
var configCtrl, scope;

beforeEach(angular.mock.module('typewritingApp'));

beforeEach(angular.mock.inject(($rootScope) => {
    scope = $rootScope.$new();
    configCtrl = new App.TestCtrl(scope);
}));

it('should be true', () => {
    expect(true).toBe(true);
});
});
module App {
import TypewritingCtrl = App.TypewritingCtrl;
import MenuCtrl = App.MenuCtrl;
var typescrip: ng.IModule;
var typewritingapp: ng.IModule = angular.module("typewritingApp", ["ngRoute", "ui.bootstrap", "LocalStorageModule", "ui.event", "timer"])
    .controller("TestCtrl", ["$scope", TestCtrl])

}
/// <reference path="../references.ts" />
module App {
export class TestCtrl {
    constructor($scope: ng.IRootScopeService) {

    }
}
}
//
模块应用程序{
导出类TestCtrl{
构造函数($scope:ng.IRootScopeService){
}
}
}
当我尝试运行测试时,karma给我写的错误是:

Firefox 41.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.089 secs / 0.119 secs)
29 09 2015 14:58:55.573:INFO [watcher]: Changed file "PROJECT_PATH/Specs/controllerSpecs.js".
Firefox 41.0.0 (Windows 10 0.0.0) ConfigCtrl should be true FAILED
    minErr/<@PROJECT_PATH/Scripts/angular.js:68:12
    loadModules/<@PROJECT_PATH/Scripts/angular.js:4411:15
    forEach@PROJECT_PATH/Scripts/angular.js:336:11
    loadModules@PROJECT_PATH/Scripts/angular.js:4372:5
    createInjector@PROJECT_PATH/Scripts/angular.js:4297:11
    workFn@PROJECT_PATH/Scripts/angular-mocks.js:2427:44
    env.executeFiltered@PROJECT_PATH/Specs/node_modules/karma-jasmine/lib/boot.js:117:7
    createStartFn/<@PROJECT_PATH/Specs/node_modules/karma-jasmine/lib/adapter.js:171:5
    [2]</Karma/this.loaded@http://localhost:9876/karma.js:190:7
    @http://localhost:9876/context.html:52:5

Firefox 41.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.255 secs / 0.103 secs)
Firefox 41.0.0(Windows 10 0.0.0):执行1/1(1失败)错误(0.089秒/0.119秒)
29 09 2015 14:58:55.573:INFO[观察者]:更改了文件“PROJECT_PATH/Specs/controllerSpecs.js”。
Firefox 41.0.0(Windows 10 0.0.0)ConfigCtrl应为true失败

Miner/我们应该要求提供服务
$rootScope
作为本地
$scope
生成器:

// beforeEach(angular.mock.inject(($scope) => {
beforeEach(angular.mock.inject(($rootScope) =>
{
    // HERE we do create a $scope from $rootScope
    scope = $rootScope.$new();
    configCtrl = new App.TestCtrl(scope);
}));

我们应该请求一个服务
$rootScope
作为本地
$scope
生成器:

// beforeEach(angular.mock.inject(($scope) => {
beforeEach(angular.mock.inject(($rootScope) =>
{
    // HERE we do create a $scope from $rootScope
    scope = $rootScope.$new();
    configCtrl = new App.TestCtrl(scope);
}));

谢谢你的回答@RadimKöhler,我已经更改了代码,但仍然收到相同的错误。我在本地复制了你的代码,它现在对我有效。我只是简化了您的模块
.module(“typewritingApp”,[])
,并实现了空
TestCtrl
。考试通过了…那我就不明白了。我已经通过NuGet软件包管理器添加了所有的de js和d.ts文件,这个例子也运行良好。这就是我的因果报应,很难说,对不起。但在您的karma文件中,我没有看到app.js或TestController.js(因为您确实调用了新的TestCtrl)…谢谢@RadimKöhler。是我的错。我没有将源文件添加到我的配置文件中,只添加了测试和脚本文件…感谢@RadimKöhler的回答,我已经更改了代码,但仍然收到相同的错误。我在本地复制了您的代码,并且它正在为我工作。我只是简化了您的模块
.module(“typewritingApp”,[])
,并实现了空
TestCtrl
。考试通过了…那我就不明白了。我已经通过NuGet软件包管理器添加了所有的de js和d.ts文件,这个例子也运行良好。这就是我的因果报应,很难说,对不起。但在您的karma文件中,我没有看到app.js或TestController.js(因为您确实调用了新的TestCtrl)…谢谢@RadimKöhler。是我的错。我没有将源文件添加到配置文件,只有测试和脚本文件。。。