我正在使用qunit和sinonjs对jquery插件进行单元测试。它在浏览器中运行得很好,所有测试都通过了,但当我使用Grunt在命令行上运行时,我得到了错误消息"PhantomJS timed out,possible to a missing QUnit start“。这个问题是由我为window.alert创建的sinonjs存根引起的。谁能解释一下我的sinon存根出了什么问题?我猜phantomjs在等回应。我尝试过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;发布于 2014-11-14 23:38:50
如果我没记错的话,您需要从存根中执行return true; (或false) ...我认为。至少,这是我一直以来的看法,也是其他answers的看法。所以试试这个:
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;https://stackoverflow.com/questions/26933257
复制相似问题