Sinon 存根超时 Phantomjs

sinon stub timing out phantomjs

本文关键字:Phantomjs 超时 存根 Sinon      更新时间:2023-09-26

我正在使用qunit和sinonjs对jquery插件进行单元测试。它在浏览器中工作正常,所有测试都通过,但是当我使用 Grunt 在命令行上运行时,我收到错误"PhantomJS 超时,可能是由于缺少 QUnit 启动"。该问题是由我为 window.alert 创建的 sinonjs 存根引起的。谁能解释一下我的 sinon 存根有什么问题?我猜 phantomjs 正在等待响应。我尝试过 QUnit.start(),也尝试从我的 sinon 存根返回真/假/未定义。

QUnit.test('test options exist and default values', function( assert ) {
    // Stub the winow alert method using sinon.
    var alertStub = sinon.stub(window, "alert", function(msg) { return true; } );
    $('#target').formdialog();
    // Assert a dialog window opened, caused by the lack of parameters passed
    sinon.assert.called(window.alert);
    // Grab the jQuery plugin data assigned to the DOM element.
    var options = $('#target').data('gten-formdialog').options;
如果我

没记错的话,你需要从你的存根中return true;(或假)......我认为。至少,我一直是这样看待它的,以及其他各种SO答案是如何看待它的。所以试试这个:

QUnit.test('test options exist and default values', function( assert ) {
// Stub the winow alert method using sinon.
var alert = sinon.stub(window, "alert", function(msg) { return true; } );
$('#target').formdialog();
// Assert a dialog window opened, caused by the lack of parameters passed
sinon.assert.called(window.alert);
// Grab the jQuery plugin data assigned to the DOM element.
var options = $('#target').data('gten-formdialog').options;