How Can I Use Html Fixtures With Karma Test Runner Using Qunit?
Solution 1:
I'm not using AngularJS... I solved by adopting jasmine-jquery: https://github.com/velesin/jasmine-jquery (I use jasmine only for the fixtures, my tests are still written using qunit). In my configuration file I have the following:
frameworks= ['qunit', 'jasmine'];files= [
JASMINE,
JASMINE_ADAPTER,
QUNIT,
QUNIT_ADAPTER,
//dependencies
{pattern:'src/main/webapp/js/libs/jquery/jquery-1.8.3.js', watched:false, served:true, included:true},
{pattern:'src/test/js/lib/jasmine-jquery.js', watched:false, served:true, included:true},
//fixtures
{pattern:'src/test/js/**/*.html', watched:true, served:true, included:false},
{pattern:'src/test/js/**/*.json', watched:true, served:true, included:false},
{pattern:'src/test/js/**/*.xml', watched:true, served:true, included:false},
//filestotest
{pattern:'src/test/js/**/*.js', watched:true, served:true, included:true}
];
then in my test files:
module("TestSuiteName", {
setup: function() {
var f = jasmine.getFixtures();
f.fixturesPath = 'base';
f.load('src/test/js/TestFixture.html');
},
teardown: function() {
var f = jasmine.getFixtures();
f.cleanUp();
f.clearCache();
}
});
Solution 2:
If you are using AngularJS, you can use the html2js preprocessor. An example how to do that is at https://github.com/vojtajina/ng-directive-testing.
These html files are served by Karma, but they are not included in the page, so you would have to fetch them - probably through xhr request.
Here is a similar preprocessor, that converts html file into a JS string (not tight to Angular): https://github.com/karma-runner/karma-html2js-preprocessor You can see how to use it in the e2e test: https://github.com/karma-runner/karma-html2js-preprocessor/tree/master/e2e-test
NOTE: this html2js preprocessor is not part of Karma 0.8 and plugins only work with Karma 0.9+ (currently in canary channel), so you have to use canary (which contains lot of changes ;-))...
Post a Comment for "How Can I Use Html Fixtures With Karma Test Runner Using Qunit?"