2012-01-13 73 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