0

当我运行以下测试时,它通过了。它应该会失败(请注意进行 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');
    ...

谢谢,大卫

4

1 回答 1

0

我最终只是等待呼叫计数达到 2。

waitsFor(function() {
  return (PageLoadingMsgCount > 1);
}, "PageLoadingMsgShown timed out", 1000);
于 2014-01-01T15:39:42.173 回答