Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Resharper运行AngularJS测试_Angularjs_Resharper_Typescript - Fatal编程技术网

使用Resharper运行AngularJS测试

使用Resharper运行AngularJS测试,angularjs,resharper,typescript,Angularjs,Resharper,Typescript,我正在尝试使用VisualStudio在Typescript中实现AngularJS应用程序。示例控制器工作正常,现在我正在尝试编写和运行一些测试。当我创建与角度无关的测试时(例如,1+1==2),它运行良好。但是,测试控制器功能似乎不起作用 这是我的tests.ts文件: /// <reference path="../scripts/typings/jasmine/jasmine.d.ts"/> /// <reference path="../scripts/typings

我正在尝试使用VisualStudio在Typescript中实现AngularJS应用程序。示例控制器工作正常,现在我正在尝试编写和运行一些测试。当我创建与角度无关的测试时(例如,
1+1==2
),它运行良好。但是,测试控制器功能似乎不起作用

这是我的
tests.ts
文件:

/// <reference path="../scripts/typings/jasmine/jasmine.d.ts"/>
/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="../scripts/typings/angularjs/angular-mocks.d.ts" />
/// <reference path="../scripts/typings/angularjs/angular-scenario.d.ts" />
/// <reference path="../app/scripts/controllers.ts"/>

'use strict';

describe("Unit controllers", () => {

    beforeEach(() => module("thisApp"));

    describe("Sample Controller", () => {

        var scope: ISampleScope;
        var ctrl;

        beforeEach(
            function() {
                inject(
                    function($rootScope: ng.IRootScopeService, $controller: ng.IControllerService) {
                        scope = <ISampleScope> $rootScope.$new();
                        ctrl = $controller('SampleCtrl', { $scope: scope });
                    }
                );
            });

        it("should have a message", () => {
            expect(element("#msg").text()).toBe("Hello");
        });

    });
})
我已经为所有引用的文件添加了
*.d.js
文件,以便自动将它们添加到源代码中,但这没有帮助

我在R#设置中的茉莉花版本是。在所有浏览器和Phantom.JS中尝试-结果同样不成功

有人设法让它工作了吗

编辑

显然,这个问题是由这样一个事实引起的:R#在所有引用之后附加Jasmine dependencies。然后,
angular mocks.js
检查
window.jasmine
,尝试注册
window.module
window.inject
,但失败


我试图预先加入我自己版本的Jasmine和一个“引导加载程序”使其初始化,这实际上解决了
模块
注入
未定义的问题,但在更深层次上引发了一系列错误。

尽管您已经包含了所有的参考注释,这将解决您在设计时的所有类型检查和自动完成要求;您还需要记住在运行时添加所有脚本,例如按正确的顺序在网页中包含所有脚本标记

你也可能会发现

  • 您缺少角度的
    标记,或者
  • 您已将其放置在测试脚本之后

  • 原来这是Resharper中的一个bug,已经修复了:

    更新到8.2.1解决了我的问题。

    R#使用自己的HTML页面进行测试,我无法修改。当引用同名的
    .d.ts
    时,我使用了包含
    .d.js
    文件的技巧,但是仍然没有帮助。我用一点调查结果更新了原始版本。
    ReferenceError: module is not defined
    ReferenceError: inject is not defined
    ReferenceError: element is not defined