Pau*_*bra 4 javascript jasmine phantomjs visual-studio-2012 resharper-7.1
感谢所有阅读此内容的人 - 这个问题有很多细节.
我正在尝试使用Jasmine将javascript测试引入我们的项目.我写的测试在浏览器中工作,但没有通过Resharper使用PhantomJS.
我猜我错过了解析我们的JS文件所需的管道(也许我正在确定我们的JS设置有问题).任何帮助非常感谢...
我使用jasmine在Visual Studio中设置了Jasmine测试...
// The Jasmine Test Framework
/// <reference path="../jquery-1.10.1.js"/>
/// <reference path="lib/jasmine-1.3.1/jasmine.css"/>
/// <reference path="lib/jasmine-1.3.1/jasmine.js"/>
/// <reference path="lib/jasmine-1.3.1/jasmine-html.js"/>
/// <reference path="lib/jasmine-jquery.js"/>
/// <reference path="lib/mock-ajax.js"/>
// Classes to test
/// <reference path="../MyNamespace.Navigation.js"/>
describe("Breadcrumbs", function () {
    it("should have a window object", function() {
        //this test passes in PhantomJS and the browser
        expect(window).toBeDefined();
    });
    it("should have the base object available", function() {
        //this test only passes in the browser
        expect(window.MyNamespace).toBeDefined();
    });
});
这引用了一个包含...的JS文件
(function (app, $, undefined) {
     //do things here
}(window.MyNameSpace = window.MyNamespace || {}, jQuery));
我有一个SpecRunner.html,它可以成功运行我的测试......它是独立的Jasmine 1.3.1附带的specrunner html,头部编辑如此......
 <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
  <script type="text/javascript" src="../jquery-1.10.1.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
  <!-- include source files here... -->
  <script type="text/javascript" src="../MyNamespace.Navigation.js"></script>
  <!-- include spec files here... -->
  <script type="text/javascript" src="spec/BreadcrumbsSpec.js"></script>
这些测试是由我的SpecRunner.html(工作正常)或通过使用PhantomJS的Resharper 7s testrunner运行的,我猜测它不会在我的JS代码文件中评估代码.?
更新:一些额外的细节......
Resharper版本是:
JetBrains ReSharper 7.1.3完整版Build 7.1.3000.2254 on 2013-04-10T16:48:18
和Phantom JS版本是1.9.1.0
我刚刚意识到我的问题中没有实际的错误 - Doh!
TypeError: 'undefined' is not an object (evaluating 'window.MyNamespace.Whatever') in http://localhost:47815/Tests.js (line 26)
TypeError: 'undefined' is not an object (evaluating 'window.MyNamespace.Whatever')
    at  BreadcrumbsSpec.js: line 26
    at  jasmine.js: line 1035
    at  jasmine.js: line 2053
    at  jasmine.js: line 2006
    at  jasmine.js: line 2335
    at  jasmine.js: line 2053
    at  jasmine.js:2043
有趣的是Tests.js不是我的文件 - 我猜这是一个R#的事情.
啊 - Tests.js是我的spec文件(即本例中的BreadcrumbsSpec.js).如果我启动开关选项告诉Resharper TestRunner使用浏览器我得到相同的结果(即只定义了窗口)和浏览器中的空白页...
Eureka ......问题是ID-ten-T,也称为PEBCAK
我没有想过或研究过R#实际上是如何运行测试的.因此,相对于我的 specrunner.html ,在Spec.js中设置了参考路径
R#实际上将Spec文件作为内联脚本注入到html页面中,因此我的相对路径都是错误的.
我只是将参考路径设置为项目根目录中的绝对路径,一切都很好.
// The Jasmine Test Framework
/// <reference path="/Scripts/jquery-1.10.1.js"/>
/// <reference path="/Scripts/tests/lib/jasmine-1.3.1/jasmine.js"/>
/// <reference path="/Scripts/tests/lib/jasmine-1.3.1/jasmine-html.js"/>
/// <reference path="/Scripts/tests/lib/jasmine-jquery.js"/>
/// <reference path="/Scripts/tests/lib/mock-ajax.js"/>
// Classes to test
/// <reference path="/Scripts/MyNamespace.Navigation.js"/>
感谢R#人在Twitter上与我交流!
| 归档时间: | 
 | 
| 查看次数: | 5164 次 | 
| 最近记录: |