0

I'm unit testing a jquery plugin using qunit and sinonjs. 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". The issue is caused by a sinonjs stub I create for window.alert. Can anyone explain what is wrong with my sinon stub? I'm guessing phantomjs is waiting for a response. I have tried QUnit.start() and also tried returning true/false/undefined from my sinon stub.

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;
Rimian
  • 36,864
  • 16
  • 117
  • 117
Charles Jackson
  • 115
  • 1
  • 2
  • 12

1 Answers1

0

If I recall correctly, you need to 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;
Community
  • 1
  • 1
Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
  • Thanks for your feedback, greatly appreciated. Unfortunately not the answer :-( Still got the same issue but I have amended the code above to reflect my latest attempts. – Charles Jackson Nov 14 '14 at 15:51
  • Dang... how about trying to mock out the `assert` method yourself just to confirm that it is Sinon that is the problem? You could just do: `window.alert = function() { return true; };` NOTE: if you try that, your assertion won't really work, but this will tell you if Phantom times out or not. – Jordan Kasper Nov 14 '14 at 17:07