【发布时间】:2015-05-03 22:15:27
【问题描述】:
我正在尝试使用带有此代码 (requirebin) 的 sinon.js 来监视 WebSocket 构造:
sinon = require('sinon');
sinon.spy(window, 'WebSocket');
// throws an error (see console)
new window.WebSocket("ws://example.com");
在 Chrome 中它失败了 Uncaught TypeError: Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
在 Safari 或 PhantomJs 中失败并显示 TypeError: Attempted to wrap object property WebSocket as function
我做错了什么?
【问题讨论】:
标签: javascript testing browser websocket sinon