Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe("with console stubbing", () => {
const sandbox = sinon.sandbox.create();
beforeEach(() => sandbox.stub(console, 'warn'));
afterEach(() => sandbox.restore());
})
}
export type WindowEvent = WindowEventMap[keyof WindowEventMap];
type WindowEventListener = (e?: Partial) => any;
function stubWindowMethod(
sandbox: SinonSandbox,
method: keyof Window,
stub: (...args: any[]) => any
) {
return sandbox.stub(window, method).callsFake(stub);
}
export class WindowStub {
public sandbox = sinon.sandbox.create();
public addEventListener = stubWindowMethod(
this.sandbox, 'addEventListener',
(type: string, listener: WindowEventListener, useCapture?: boolean) => {
const events = useCapture ? this.eventsCapture : this.events;
if (events.has(type)) {
const listeners = events.get(type);
(listeners as WindowEventListener[]).push(listener);
} else {
const listeners = [listener];
events.set(type, listeners);
}
}
);
public removeEventListener = stubWindowMethod(