工作,這是我正在運行茉莉花點擊觸發不會對<a>
describe("Test", function() {
beforeEach(function(){
loadFixtures('modal.html');
});
it ("click a tag", function(){
var spy = spyOnEvent($('.modal-link'), 'click');
$('.modal-link').trigger('click');
expect('click').toHaveBeenTriggeredOn($('.modal-link'));
expect(spy).toHaveBeenTriggered();
});
});
裏面的固定裝置(modal.html)規範,它看起來像這樣
<a class="modal-link">Test Link</a>
測試失敗,此錯誤:
Expected event [object Object] to have been triggered on [object Object]at Object.<anonymous>
Expected event click to have been triggered on [object Object] at Object.<anonymous>
但是,當我用div,span或p替換標記時,測試通過。
<div class="modal-link">Test Link</div>
是否有某些原因在我的測試中標記不可點擊?在19/04
編輯: 我用噶運行測試,這裏的配置文件
module.exports = function(config) {
config.set({
frameworks: ['jquery-1.11.0', 'jasmine-jquery', 'jasmine'],
reporters: ['mocha'],
browsers: ['PhantomJS'],
plugins: [
// Karma will require() these plugins
'karma-jasmine',
'karma-jasmine-jquery',
'karma-jquery',
'karma-phantomjs-launcher',
'karma-mocha-reporter'
],
preprocessors: {
'test/spec/**/*.html': ['html2js']
},
autoWatch: true,
files: [
{pattern: 'app/libs/jquery.min.js', watched: true, included: true, served: true},
{pattern: 'app/libs/bootstrap/js/bootstrap.js', watched: true, included: true, served: true},
{pattern: 'app/js/myjavascript.js', watched: true, included: true, served: true},
{pattern: 'test/spec/**/*.js', watched: true, included: true, served: true},
{pattern: 'test/spec/**/*.html', watched: true, included: false, served: true}
],
});
};
你在使用瀏覽器在你的測試? – MBielski
jasmine默認不瞭解jquery方法,你使用jq jasmine庫嗎? –
@MBielski,我試過Chrome,Firefox和PhantomJS,但測試一直失敗。 –