简体   繁体   English

sinon存根超时phantomjs

[英]sinon stub timing out phantomjs

I'm unit testing a jquery plugin using qunit and sinonjs . 我正在使用qunit和sinonjs对jquery插件进行单元测试。 It works fine in the browser, all tests pass but when I run on the command line using Grunt I get the error "PhantomJS timed out, possible due to a missing QUnit start". 它在浏览器中运行良好,所有测试均通过,但是当我使用Grunt在命令行上运行时,出现错误“ PhantomJS超时,可能是由于缺少QUnit启动引起的”。 The issue is caused by a sinonjs stub I create for window.alert. 问题是由我为window.alert创建的sinonjs存根引起的。 Can anyone explain what is wrong with my sinon stub? 谁能解释我的sinon存根有什么问题? I'm guessing phantomjs is waiting for a response. 我猜phantomjs正在等待响应。 I have tried QUnit.start() and also tried returning true/false/undefined from my sinon stub. 我尝试过QUnit.start(),还尝试从sinon存根返回true / false / undefined。

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;

If I recall correctly, you need to return true; 如果我没记错的话,您需要return true; (or false) from your stub... I think. (或错误)来自您的存根...我想。 At least, that's how I've always seen it, and how various other SO answers have it. 至少,这就是我一直看到的方式,以及其他各种 答案如何。 So try this: 所以试试这个:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM