.toHaveBeenCalled()true应该为false

时间:2013-12-31 18:33:38

标签: jquery-mobile jasmine jasmine-jquery

当我运行以下测试时,它会通过。它应该失败(注意发出tap()调用的注释行)。它只应在tap()调用时通过。有没有人知道为什么$ .mobile.loading显示为在我不发送tap()事件时被调用?

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');
    ...

谢谢, 大卫

1 个答案:

答案 0 :(得分:0)

我刚结束等待通话数达到2。

waitsFor(function() {
  return (PageLoadingMsgCount > 1);
}, "PageLoadingMsgShown timed out", 1000);