【问题标题】:Where do I put HTML fixtures when I'm using JsTestDriver?当我使用 JsTestDriver 时,我应该把 HTML 固定装置放在哪里?
【发布时间】:2012-06-05 22:43:48
【问题描述】:

我很难让 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);
        });

    });

});

我的控制台输出是:

(link to full-size image)

我查看了this question,但它并没有帮助我弄清楚。奇怪的是,当我注释掉

loadFixtures('index.html');

行,测试通过。

有什么想法吗?

【问题讨论】:

    标签: jasmine jasmine-jquery js-test-driver


    【解决方案1】:

    好的——想通了。 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。

    【讨论】:

      【解决方案2】:

      尝试将夹具路径更改为:

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

      否则我会得到不同但类似奇怪的错误。

      【讨论】:

      • 然后我得到“错误:无法加载夹具:/fixtures/index.html(状态:错误,消息:未定义)”。无论如何谢谢:)
      • 你最终解决了这个问题吗?我得到了那个确切的错误,虽然有时它会变成浏览器恐慌错误
      • 嘿,戴夫——我在上面添加了我的答案,以防你还在寻找。
      猜你喜欢
      • 2020-09-30
      • 1970-01-01
      • 2016-08-25
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2019-07-11
      相关资源
      最近更新 更多