我没有使用 AngularJS ...我通过采用 jasmine-jquery 解决了:https ://github.com/velesin/jasmine-jquery (我仅将 jasmine 用于固定装置,我的测试仍然使用 qunit 编写)。在我的配置文件中,我有以下内容:
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}
];
然后在我的测试文件中:
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();
}
});