简体   繁体   English

使用Jasmine和Chutzpah在Visual Studio中测试TypeScript和AngularJS-找不到变量:angular

[英]Testing TypeScript and AngularJS in Visual Studio with Jasmine and Chutzpah - can't find variable: angular

I'm trying to test my TypeScript and AngularJS code with Jasmine in Visual Studio Chutzpah. 我正在尝试在Visual Studio Chutzpah中使用Jasmine测试我的TypeScript和AngularJS代码。 Test is running correctly in karma, but I realy like Chutzpah's UI. 测试可以在业力中正常运行,但是我真的很喜欢Chutzpah的UI。

My controllerSpecs.ts : 我的controllerSpecs.ts

/// <chutzpah_reference path="../Scripts/angular.js" />
/// <chutzpah_reference path="../Scripts/angular-mocks.js" />
/// <chutzpah_reference path="../Scripts/angular-route.js" />
/// <chutzpah_reference path="../Scripts/angular-resource.js" />
/// <chutzpah_reference path="../Scripts/angular-local-storage.js" />
/// <chutzpah_reference path="../Controllers/MenuController.js" />
/// <chutzpah_reference path="../App/app.js" />
/// <chutzpah_reference path="../references.js" />
/// <reference path="../references.ts" />

describe('Controller Specs', () => {

describe('Menu Controller Specs', () => {
    var menuCtrl, scope;

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

    beforeEach(() => inject(($rootScope) => {

        scope = $rootScope.$new();
        menuCtrl = new App.MenuCtrl(scope);
    }));

    it('should be true', () => {
        expect(true).toBe(true);
    });
});

});

My app.ts : 我的app.ts

module App {
var typewritingapp: ng.IModule = angular.module("typewritingApp", [])
    .controller("MenuCtrl", ["$scope", MenuCtrl])
}

My MenuController.ts : 我的MenuController.ts

module App {

export class MenuCtrl {
    constructor($scope: any) {
        $scope.pageTitle = "Menu";
    }
}
}

If I change the angular.mock.module part to module in the test (and I also need to modify the angular-mocks.d.ts to declare module) I receive the same error but it doesn't find variable: module. 如果在测试中将angular.mock.module部分更改为module (并且还需要修改angular-mocks.d.ts来声明module),我会收到相同的错误,但找不到变量:module。

I had a wrong karma config file and after it has started to work I forgot to update chutzpah.json so it was my fault. 我有一个错误的业力配置文件,在它开始工作后,我忘了更新chutzpah.json,所以这是我的错。 Thanks for the help @MatthewManela 感谢@MatthewManela的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM