dimanche 3 mai 2015

Sinon spy on WebSocket

I am trying to spy on WebSocket construction using sinon.js with this code (requirebin):

sinon = require('sinon');

sinon.spy(window, 'WebSocket');
// throws an error (see console)
new window.WebSocket("ws://example.com");

In Chrome it fails with Uncaught TypeError: Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function. In Safari or PhantomJs it fails with TypeError: Attempted to wrap object property WebSocket as function

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire