JStestDriverを使用しているときにHTMLフィクスチャーをどこに配置しますか?

StackOverflow https://stackoverflow.com/questions/8858543

質問

JSTDにフィクスチャー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

(フルサイズの画像へのリンク)

私は見た この質問 しかし、それは私がそれを理解するのを助けませんでした。奇妙なことは、私がコメントするときです

loadfixtures( 'index.html');

ライン、テストが通過します。

何か案は?

役に立ちましたか?

解決

わかりました - それを理解しました。 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() コールは、HTMLフィクスチャに絶対URLを使用します。

他のヒント

フィクスチャパスを次のように変更してみてください。

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

そうでない場合も同様に奇妙なエラーが発生します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top