Search code examples
javascriptqunitsinon

Sinon alert stub: "Attempted to wrap alert which is already wrapped"


I'm using Sinon 1.14. I would like to suppress all javascript alerts using Sinon's stubs.

Using the latest Chrome version: 42.0.2311.135 m, I get an exception: "Attempted to wrap alert which is already wrapped"

The code below works fine in latest Firefox. I will update with a fiddle.

var hooks = {

    beforeEach: function(assert){
        this.sandbox = sinon.sandbox.create();
        this.sandbox.stub(window, 'alert', function (msg) { return false; });
    },

    afterEach: function(){
        this.sandbox.restore();
    }
};

module('example', hooks);

test('example', function(assert){
    ok(true, 'does not throw an exception');
});

Solution

  • Updating Sinon from 1.14 to 1.14.1 seems to do the trick. I assume this was a bug?

    As a side note, the code runs fine in 1.12 as well.