WebStorm – Jasmine jQuery

我对WebStorm的使用还很陌生,但它没有像预期的那样工作。 我过去有一个项目,但现在我尝试重新创建它并尝试对我的代码进行unit testing。 我对unit testingJavaScript代码非常陌生。

所以,我有一个文件karma.conf.js ,其中包含以下内容:

 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代码上加载fixture。

所以,我有一个JavaScript函数,可以在按下或释放按钮时切换类:

 $(function() { $('#OfficeUI a.button').on('mousedown mouseup', function(e) { $(this).toggleClass('ie-fix'); }); }); 

现在,我编写了一个unit testing,如下所示:

 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); }); }); 

在此处输入图像描述

下图显示了我项目的文件夹结构。

现在,当我运行我的测试时,我收到以下错误:

 Error: Fixture could not be loaded: spec/javascripts/fixtures/OfficeUI.Elements.Test.html (status: error, message: undefined) 

我试图通过更改unit testing中的beforeEach方法来解决这个问题,如下所示:

 beforeEach(function() { jasmine.getFixtures().fixturesPath = '/OfficeUI.Beta/Unit Tests/Pages'; loadFixtures('OfficeUI.Elements.Test.html'); }); 

我在fixturesPath尝试过各种各样的东西但是我一直收到同样的错误。

任何人都知道如何解决这个问题? 任何帮助都非常感谢。

编辑:更新了karma配置:

 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文件中更改以下行:

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

至:

 jasmine.getFixtures().fixturesPath = 'base/Tests/'; 

这对我来说很好

在我的业力配置文件中,我必须告诉业力它为茉莉花提供夹具文件。

尝试在karma配置文件的files部分插入以下内容:

  // fixtures { pattern: '../../Resources/Unit Tests/Pages/*.*', watched: true, served: true, included: false },