首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sinon存根超时phantomjs

sinon存根超时phantomjs
EN

Stack Overflow用户
提问于 2014-11-14 23:22:35
回答 1查看 411关注 0票数 0

我正在使用qunit和sinonjs对jquery插件进行单元测试。它在浏览器中运行得很好,所有测试都通过了,但当我使用Grunt在命令行上运行时,我得到了错误消息"PhantomJS timed out,possible to a missing QUnit start“。这个问题是由我为window.alert创建的sinonjs存根引起的。谁能解释一下我的sinon存根出了什么问题?我猜phantomjs在等回应。我尝试过QUnit.start(),也尝试过从sinon存根返回true/false/undefined。

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2014-11-14 23:38:50

如果我没记错的话,您需要从存根中执行return true; (或false) ...我认为。至少,这是我一直以来的看法,也是其他answers的看法。所以试试这个:

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26933257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档