gpt4 book ai didi

jasmine-jquery 不会加载任何夹具

转载 作者:行者123 更新时间:2023-12-04 10:24:42 25 4
gpt4 key购买 nike

我正在使用 karma + Jasmine + jquery + Jasmine jquery
我有几个纯 js 单元测试,现在是时候继续编写一些 html 相关测试了。
我尝试了 jasmine-jquery 及其 loadFixtures,但无论我尝试什么,我仍然收到错误消息,没有任何有用的消息。

我创建了一个简单的项目来单独测试事物,这是我的设置:

.
├── karma.conf.js
├── package.json
├── spec
│   └── javascripts
│   └── fixtures
│   └── simple.test.html
└── src
└── test
└── js
└── simple.test.js

包.json
{
"dependencies": {
"karma": "0.12.31",
"jasmine": "2.1.1",
"karma-jasmine": "0.3.5",
"jasmine-jquery": "2.0.6",
"karma-jasmine-jquery": "0.1.1",
"karma-teamcity-reporter": "0.1.2"
},
"devDependencies": {
"karma-chrome-launcher": "~0.1.7",
"karma-firefox-launcher": "~0.1.4"
}
}

规范/javascripts/fixtures/simple.test.html
<body>
Test
</body>

src/test/js/simple.test.js
describe('simple', function () {
beforeEach(function () {
loadFixtures('simple.test.html');
});

it('test', function () {
expect(true).toBeTruthy();
});
});

我收到此错误
Chrome 27.0.1453 (Linux) simple test FAILED
Error: Fixture could not be loaded: spec/javascripts/fixtures/simple.test.html (status: error, message: undefined)
at Object.<anonymous> (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:133:17)
at fire (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3094:30)
at Object.self.add (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3140:7)
at jasmine.Fixtures.loadFixtureIntoCache_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:132:10)
at jasmine.Fixtures.getFixtureHtml_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:115:12)
at jasmine.Fixtures.read (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:77:28)
at jasmine.Fixtures.load (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:65:37)
at jasmine.Fixtures.proxyCallTo_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:161:29)
at window.loadFixtures (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:765:27)


Firefox 24.0.0 (Linux) simple test FAILED
Error: Fixture could not be loaded: spec/javascripts/fixtures/simple.test.html (status: error, message: undefined) in /tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js (line 133)
jasmine.Fixtures.prototype.loadFixtureIntoCache_/request<@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:133
jQuery.Callbacks/fire@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3094
jQuery.Callbacks/self.add@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3140
jasmine.Fixtures.prototype.loadFixtureIntoCache_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:132
jasmine.Fixtures.prototype.getFixtureHtml_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:115
jasmine.Fixtures.prototype.read@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:77
jasmine.Fixtures.prototype.load@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:65
jasmine.Fixtures.prototype.proxyCallTo_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:161
window.loadFixtures@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:765
@/tmp/zkurv/src/test/js/simple.test.js:3

有什么帮助吗?

最佳答案

需要在 karma.conf.js 的文件列表中定义夹具。 Karma 提供/base 目录下的文件:
http://karma-runner.github.io/0.8/plus/RequireJS.html .

我已经按照您的方式设置了项目,在 karma.conf.js 中定义了夹具,我可以通过 Karma 启动的浏览器手动访问夹具:
http://localhost:9876/base/spec/javascripts/fixtures/simple.test.html .

需要在 Jasmine 中设置默认设备路径:

jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';
loadFixtures('simple.test.html');

关于jasmine-jquery 不会加载任何夹具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28562448/

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