我沒有使用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();
}
});
檢查我的答案在這裏:http://stackoverflow.com/questions/15214760/unit-testing- angularjs-directive-with-templateurl/16528985#16528985 – 2013-05-13 19:04:42