当我运行以下测试时,它通过了。它应该会失败(请注意进行 tap() 调用的注释行)。它只应该在进行 tap() 调用时通过。有人知道为什么在我不发送 tap() 事件时 $.mobile.loading 显示为已被调用吗?
beforeEach(function() {
jasmine.getFixtures().fixturesPath = ".";
loadFixtures('index.html');
});
/* this test is buggy - it passes even when the tap() method is not called */
it("should display a PageLoadingMsg", function() {
var PageLoadingMsgCount = 0;
runs(function() {
$('#account_creation').trigger('pageinit');
console.log('d');
spyOn($.mobile, 'loading').andCallFake(function() {
PageLoadingMsgCount++;
console.log('a');
});
console.log('e');
spyOn($.mobile, 'hidePageLoadingMsg');
spyOn($.mobile, 'changePage');
});
runs(function() {
expect($('#account_creation_create_account_button')).toHaveAttr('data-role','button');
// $('#account_creation_create_account_button').tap();
});
waitsFor(function() {
return (PageLoadingMsgCount > 0);
}, "PageLoadingMsgShown timed out", 1000);
runs(function() {
expect($.mobile.loading).toHaveBeenCalled();
console.log(PageLoadingMsgCount);
expect(PageLoadingMsgCount).toBeGreaterThan(0);
});
});
这是它试图监视的电话:
$(document).on('pageinit', '#account_creation', function(event) {
$(document).on('tap', '#account_creation_create_account_button', function(event) {
event.stopImmediatePropagation();
event.preventDefault();
console.log('b');
$.mobile.loading('show', {theme:settings['theme'], text:"Creating account..."});
console.log('c');
...
谢谢,大卫