我正在尝试使用jasmine-jquery进行UI测试。我使用karma作为我的测试运行程序,使用jasmine作为我的测试框架。我想我已经成功地加载了fixture,并且jasmine-jquery在我的karma配置中被列为测试框架。
但是,我无法使用jasmine-jquery在DOM中找到元素。为什么?
目录结构
base
spec
javascripts
fixtures
myfixture.html
karma.conf.js
tests
settingUpHTMLFixtures.test.jsmyfixture.html
<div id="my-fixture">foo bar</div>settingUpHTMLFixtures.test.js
jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';
loadFixtures('myfixture.html');
describe('testing out jasmine-jquery', function(){
it('can find an element in the dom using jasmine-jquery', function(){
expect($j('#my-fixture')).toBeInDOM();
})
})karma.conf.js
const webpackConfig = require('./webpack.config.js');
module.exports = function(config) {
config.set({
basePath: "",
files: ["tests/**/*.test.js", 'spec/javascripts/fixtures/*.html'],
frameworks: ['jasmine-jquery', 'jasmine', 'jasmine-matchers'],
preprocessors: {
"tests/**/*.test.js": ["webpack"]
},
webpack: webpackConfig,
plugins : [
'karma-chrome-launcher',
'karma-jasmine',
'karma-jasmine-jquery',
'karma-jasmine-matchers',
'karma-webpack',
'karma-jasmine-html-reporter'
],
logLevel: config.LOG_INFO,
reporters: ['kjhtml'],
port: 9876,
browsers: ["Chrome"],
//...
});
};目前,我得到的消息是测试失败,即testing out jasmine-jquery can find an element in the dom using jasmine-jquery FAILED Expected jQuery({ context: HTMLNode, selector: '#my-fixture' }) to be in d o m. at UserContext.<anonymous> (tests/settingUpHTMLFixtures.test.js:78:31)"
发布于 2017-12-01 02:53:10
我有一个路径错误。我自己创建基目录是一个错误。Karma只是提供基本目录中的所有内容。
我唯一需要使用单词base的时候是在设置fixtures路径时(如上面的settingUpHTMLFixtures.test.js代码所示)。
https://stackoverflow.com/questions/47561902
复制相似问题