问题描述
我对WebStorm的用法很陌生,但并未按预期工作.过去我有一个项目,但是现在我尝试重新创建它并尝试对代码进行单元测试.我是单元测试JavaScript代码的新手.
I'm quite new to the usage of WebStorm, but it's not working as epected. I had a project in the past, but now I try to recreate it and try to unit test my code.I'm very new to unit testing JavaScript code.
因此,我有一个文件karma.conf.js
,其中包含以下内容:
So, I have a file karma.conf.js
which contains the following:
module.exports = function(config){
config.set({
basePath : './',
files : [
'../../Resources/External/Bower/angular/angular.js',
'../../Resources/External/Bower/angular-mocks/angular-mocks.js',
'../../Resources/Scripts/OfficeUI.js',
'../../Unit Tests/**/*.Test.js'
],
autoWatch : true,
frameworks: ['jasmine-jquery', 'jasmine'],
browsers : ['Chrome']
});
};
因此,我确实使用Jasmine框架对Karma进行了测试.我包含了jasmine-jquery
以便将灯具加载到我的HTML代码上.
So, I do run my tests with Karma using the Jasmine framework. I've included jasmine-jquery
in order to load fixtures to my HTML code on it.
所以,我有一个JavaScript函数,可以在您按下或释放按钮时切换一个类:
So, I do have a JavaScript function which toggles a class when you press or release the button:
$(function() {
$('#OfficeUI a.button').on('mousedown mouseup', function(e) {
$(this).toggleClass('ie-fix');
});
});
现在,我编写了一个如下所示的单元测试:
Now, I have written a Unit Test which looks like the following:
describe("Unit: OfficeUI Elements", function() {
// Load up the HTML page 'OfficeUI.Elements.Test.html' before every test is executed.
beforeEach(function() {
loadFixtures('OfficeUI.Elements.Test.html');
});
it("should do some stuff in this example", function() {
expect(true).toEqual(true);
});
});
下面的图像确实显示了我项目的文件夹结构.
The image below does show the folder structure of my project.
现在,当我运行测试时,确实收到以下错误:
Now, When I do run my tests, I do receive the following error:
Error: Fixture could not be loaded: spec/javascripts/fixtures/OfficeUI.Elements.Test.html (status: error, message: undefined)
我试图通过更改单元测试中的beforeEach
方法来解决此问题,如下所示:
I've tried to resolve this by changing the beforeEach
method in the Unit Test like the following:
beforeEach(function() {
jasmine.getFixtures().fixturesPath = '/OfficeUI.Beta/Unit Tests/Pages';
loadFixtures('OfficeUI.Elements.Test.html');
});
我已经尝试过fixturesPath
中的各种操作,但是我仍然收到相同的错误.
I've tried various things in the fixturesPath
but I keep receiving the same error.
有人对如何解决这个问题有想法吗?任何帮助都将受到高度赞赏.
Anyone has an idea on how to solve this?Any help is highly appreciated.
更新了业力配置:
module.exports = function(config){
config.set({
basePath : '../../',
files : [
'Resources/External/Bower/jquery/dist/jquery.js',
'Resources/External/Bower/angular/angular.js',
'Resources/External/Bower/angular-mocks/angular-mocks.js',
'Resources/Scripts/OfficeUI.js',
'Resources/Scripts/Elements/OfficeUI.Elements.js',
'Unit Tests/**/*.Test.js',
{ pattern: 'Resources/Unit Tests/*.html', watched: true, served: true, included: false },
],
autoWatch : true,
watched: true,
server: true,
include: false,
frameworks: ['jasmine-jquery', 'jasmine'],
browsers: ['Chrome']
});
};
推荐答案
在OfficeUI.Elements.Test.js文件中更改以下行:
Change in your OfficeUI.Elements.Test.js file the following line:
jasmine.getFixtures().fixturesPath = '/Tests/';
收件人:
jasmine.getFixtures().fixturesPath = 'base/Tests/';
对我来说很好
这篇关于WebStorm-茉莉jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!