samedi 7 mars 2015

WebStorm - Jasmine jQuery

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.


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


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.


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


enter image description here


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)


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


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.


Aucun commentaire:

Enregistrer un commentaire