与ReSharper的AngularJS单元测试 [英] AngularJS unit testing with ReSharper

查看:282
本文介绍了与ReSharper的AngularJS单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让茉莉花单元测试与ReSharper的测试运行器中运行的AngularJS控制器,这样我就可以在VS 2012中的一个地方运行我的客户端和服务器端的测试。

I'm trying to get Jasmine unit tests for an AngularJS controller running with the ReSharper test runner so I can run my client and server-side tests in one place within VS 2012.

我运行到哪里ReSharper的测试运行与的消息失败的问题不确定:测试没有运行。同样的测试运行正常使用自带的AngularJS种子项目的测试运行。

I'm running into an issue where the ReSharper test runner is failing with a message of "Inconclusive: Test wasn't run". The same test runs fine using the test runner that comes with the AngularJS Seed project.

下面是我的故障排除简单的测试:

Here's my simple test for troubleshooting:

/// <reference path="~/Scripts/angular/angular.js"/>
/// <reference path="~/tests/test/lib/angular/angular-mocks.js"/>
/// <reference path="~/Scripts/app/controllers.js"/>

'use strict';

describe('controllers', function(){
  beforeEach(module('myApp.controllers'));

  it('should ....', inject(function() {
      expect(1).toEqual(1);
  }));
});

我怀疑它是与我引用这样做,因为如果我删除调用,我的测试运行良好。然而,在角mocks.js(这我引用)的定义,所以我不知道是什么问题。

I suspect it has something to do with my references because if I remove the call to inject, my test runs fine. However, inject is defined in angular-mocks.js (which I'm referencing) so I'm not sure what the problem is.

有什么建议?

推荐答案

您预感约ReSharper的绊倒内联是正确的,它似乎期望功能,而不是当它分析文件,以获得测试名单。我通过移动工作围绕 s转换为 beforeEach 或进入体内的这让ReSharper的开心了。顺便说一句,我还添加引用的 jasmine.js 的顶部(前其他参考资料)摆脱了ReSharper的有关未定义茉莉花全局警告。

Your hunch about ReSharper tripping over inline inject is right, it seems to expect function instead when it parses file to get list of tests. I've worked around by moving injects into either beforeEach or into the body of the it and that made ReSharper happy again. Btw, I've also added reference to jasmine.js at the top (before other references) to get rid of ReSharper's warnings about undefined Jasmine globals.

这篇关于与ReSharper的AngularJS单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆