AngularJS unit testing with ReSharper

南笙酒味 提交于 2020-01-03 08:32:22

问题


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.

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);
  }));
});

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.

Any suggestions?


回答1:


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.




回答2:


There is an issue about this ReSharper problem at their tracker at http://youtrack.jetbrains.com/issue/RSRP-383328 - you can vote for it to be fixed.




回答3:


Take a look to this page. I disabled the option "Shadow-copy assemblies being tested", and it worked. Test method is inconclusive: Test wasn't run. Error?




回答4:


ReSharper set file jasmine.js after all references. angular-mock.js will not find jasmine and will skip creation window.module and window.injec functions

I created jasmine2.js and set it as first reference. I did empty jasmine.js and set it as second reference.

After all my test did work



来源:https://stackoverflow.com/questions/17618923/angularjs-unit-testing-with-resharper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!