2012-01-13 78 views
4

我很难让JSTD加载一个夹具HTML文件。当我使用JsTestDriver时,我在哪里放置HTML装置?

我的目录结构是:

localhost/JsTestDriver.conf 
localhost/JsTestDriver.jar 
localhost/js/App.js 
localhost/js/App.test.js 
localhost/fixtures/index.html 

我的conf文件说:

server: http://localhost:4224 

serve: 

- fixtures/*.html 

load: 

- http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js 
- jasmine/lib/jasmine-1.1.0/jasmine.js 
- jasmine/jasmine-jquery-1.3.1.js 
- jasmine/jasmine-jstd.js 
- js/App.js 

test: 

- js/App.test.js 

我的测试是:

describe("App", function(){ 

    beforeEach(function(){ 
     jasmine.getFixtures().fixturesPath = 'fixtures'; 
     loadFixtures('index.html'); **//THIS LINE CAUSES IT TO FAIL** 
    }); 

    describe("When App is loaded", function(){ 

     it('should have a window object', function(){ 
      expect(window).not.toBe(null); 
     }); 

    }); 

}); 

我的控制台输出为:

enter image description here

link to full-size image

我看着this question但它并没有帮助我找到答案。奇怪的是,当我注释掉

loadFixtures('index.html');

行,测试通过。

任何想法?

回答

2

好的 - 算出来了。 JsTestDriver预先“测试”到您的灯具路径。

另外,jasmine-jquery获取使用ajax的灯具。

因此,这些措施终于为我工作:

在jsTestDriver.conf:

serve: 
- trunk/wwwroot/fixtures/*.html 

load: 

    - trunk/wwwroot/js/libs/jquery-1.7.1.min.js 
    - jstd/jasmine/standalone-1.2.0/lib/jasmine-1.2.0/jasmine.js 
    - jstd/jasmine-jstd-adapter/src/JasmineAdapter.js 
    - jstd/jasmine-jquery/lib/jasmine-jquery.js 

    - trunk/wwwroot/js/main.js 

test: 

    - trunk/wwwroot/js/main.test.js 

在我的测试文件:

describe("main", function(){ 

    beforeEach(function(){ 
     jasmine.getFixtures().fixturesPath = '/test/trunk/wwwroot/fixtures'; 
     jasmine.getFixtures().load('main.html'); 
    }); 

    describe("when main.js is loaded", function(){ 

     it('should have a div', function(){ 
      expect($('div').length).toBe(1); 
     }); 

    }); 

}); 

注意,beforeEach()调用使用绝对URL到HTML灯具。

0

尝试改用夹具路径:

jasmine.getFixtures().fixturesPath = '/fixtures'; 

我得到不同的,但在其他方面同样奇怪的错误。

+0

然后我得到“错误:Fixture无法加载:/fixtures/index.html(status:error,message:undefined)”。无论如何感谢:) – marclar 2012-01-18 22:11:14

+0

你最终解决这个问题吗?我得到了确切的错误,虽然有时它会更改为浏览器错误 – 2012-03-08 23:40:34

+0

嘿,戴夫 - 我在上面添加了我的答案,以防您仍在寻找。 – marclar 2012-06-05 14:44:24