How can I use HTML fixtures with Karma test runner using Qunit?

前端 未结 2 526
谎友^
谎友^ 2020-12-13 04:53

I\'m playing with Karma test runner (http://karma-runner.github.io/0.8/index.html) using qunit (http://qunitjs.com). I succesfully created

2条回答
  •  执笔经年
    2020-12-13 05:04

    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},
    
          // files to test 
          {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();
        }
    });
    

提交回复
热议问题