javascript - How can I use HTML fixtures with Karma test runner using Qunit? -
i'm playing karma test runner (http://karma-runner.github.io/0.8/index.html) using qunit (http://qunitjs.com). succesfully created , ran simple tests (100% javascript), i'm trying use html fixtures in order test code interacts dom nodes. i'm able load these fixtures declaring them in "files" in way:
{pattern: 'fixtures/myfixture.html', watched: true, served: true, included: false}
it served karma's server, don't understand how can access dom :(
let's suppose fixture simple html file containing following markup:
<div id="container">hello world</div>
how can write test can access node (the div)? "document" related "context.html" file under "static" folder far know... html of fixture??
i'm not using angularjs... solved adopting jasmine-jquery: https://github.com/velesin/jasmine-jquery (i use jasmine fixtures, tests still written using qunit). in configuration file have 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}, // files test {pattern: 'src/test/js/**/*.js', watched: true, served: true, included: true} ];
then in 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(); } });