How to use the test-drive-react.sinon.sandbox function in test-drive-react

To help you get started, we’ve selected a few test-drive-react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wix / wix-react-tools / test / react-decor / react-decor-reflection.spec.tsx View on Github external
describe("with console stubbing", () => {
                const sandbox = sinon.sandbox.create();
                beforeEach(() => sandbox.stub(console, 'warn'));
                afterEach(() => sandbox.restore());
            })
        }
github wix-playground / stylable-components / test-kit / stubs / window.stub.ts View on Github external
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(