gpt4 book ai didi

jasmine - 当我使用 JsTestDriver 时,我应该在哪里放置 HTML 固定装置?

转载 作者:行者123 更新时间:2023-12-02 10:08:32 25 4
gpt4 key购买 nike

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

( link to full-size image )

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

loadFixtures('index.html');

行,测试通过。

有什么想法吗?

最佳答案

好的——明白了。 JsTestDriver 将“test”添加到您的装置的路径中。

此外,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 - 当我使用 JsTestDriver 时,我应该在哪里放置 HTML 固定装置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8858543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com