How to use test-drive-react - 10 common examples

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 / core / functional.spec.ts View on Github external
it('calls the two handlers with the arguments provided', () => {
        const spy1 = sinon.spy();
        const spy2 = sinon.spy();
        const merged = serialize(spy1, spy2);

        // not call handlers in merging phase
        expect(spy1).to.have.callCount(0);
        expect(spy2).to.have.callCount(0);

        merged(...ARGS);
        // call handlers when calling merged function
        expect(spy1).to.have.callCount(1);
        expect(spy1).to.have.calledWithExactly(...ARGS);
        expect(spy2).to.have.callCount(1);
        expect(spy2).to.have.calledWithExactly(...ARGS);
    });
github wix / wix-react-tools / test / react-decor / class-component.spec.tsx View on Github external
describe.assuming(inBrowser(), 'only in browser')('react-decor-class', () => {
    describe.assuming(inProduction(), 'only in production mode')('react contract regression tests', () => {
        it('in production mode', () => {
            // This test either passes or is ignored. It's here as a log artifact, to know whether other tests run in production mode
            expect(process.env.NODE_ENV).to.eql('production');
        });
    });
    const clientRenderer = new ClientRenderer();
    afterEach(() => clientRenderer.cleanup());


    function fooHook<p>&gt;(_props: object, args: ElementArgs</p><p>) {
        args.newProps['data-foo'] = 'foo';
        return args;
    }

    function barHook</p><p>&gt;(_props: object, args: ElementArgs</p><p>) {
        args.newProps['data-bar'] = 'bar';
        return args;
    }

    const fooDecorator = reactDecor.onEachElement(fooHook);
    const barDecorator = reactDecor.onEachElement(barHook);
</p>
github wix / wix-react-tools / test / react-decor / react-decor-reflection.spec.tsx View on Github external
it("should work with custom symbols", () => {
                const wrapper3 = reactDecor.makeFeature([hook]);
                const symbol = {};
                featuresApi.markFeatureWith(wrapper3, symbol);
                const anotherWrappedComp = wrapper3(Comp);

                expect(reactDecor.isDecorated(anotherWrappedComp, symbol), 'isDecorated by known symbol').to.equal(true);
                expect(reactDecor.isDecorated(anotherWrappedComp, {}), 'isDecorated by unknown symbol').to.equal(false);
            });
github wix / wix-react-tools / test / class-decor / side-effects.spec.ts View on Github external
it("reflects decoration well", () => {
        expect(classDecor.isDecorated(Foo), 'Foo').to.equal(false);
        expect(classDecor.isDecorated(Bar), 'Bar').to.equal(true);
        expect(classDecor.isDecorated(Biz), 'Biz').to.equal(true);
        expect(classDecor.isDecorated(Baz), 'Baz').to.equal(true);
    });
github wix / wix-react-tools / test / class-decor / inheritance.spec.ts View on Github external
it(runId, () => {
                resetAll(SPIES);
                const obj = objProvider();
                const result = obj.myMethod(ORIGIN_ARGUMENT);
                expect(SPIES.firstBefore).to.have.callCount(1).and.calledWith(sinon.match.same(obj), [ORIGIN_ARGUMENT]);
                expect(SPIES.lastBefore).to.have.callCount(1).and.calledWith(sinon.match.same(obj), [ORIGIN_ARGUMENT + 1]);
                expect(SPIES.superClassFunction).to.have.callCount(0);
                expect(SPIES.childFunction).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_ARGUMENT + 2);
                expect(SPIES.firstAfter).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_RESULT);
                expect(SPIES.lastAfter).to.have.callCount(1).and.calledWith(sinon.match.same(obj), ORIGIN_RESULT + 1);
                expect(result).to.equal(ORIGIN_RESULT + 2);
            });
        }
github wix / wix-react-tools / test / react-decor / react-decor-reflection.spec.tsx View on Github external
it("should return true for a wrapped component", () => {

                expect(reactDecor.isDecorated(WrappedComp)).to.equal(true);
            });
github wix / wix-react-tools / test / function-decor / warnings.spec.ts View on Github external
beforeEach("replace console.warn with spy", () => {
        console.warn = sinon.spy();
    });
github wix-playground / stylable-components / test / components / global-event.spec.tsx View on Github external
it('should call all appropriate handlers', () =&gt; {
            const onMouseDown = sinon.spy();
            const onMouseMove = sinon.spy();
            const onMouseUp = sinon.spy();

            clientRenderer.render(
                
            );

            windowStub.simulate('mousedown');
            windowStub.simulate('mousemove');
            windowStub.simulate('mouseup');

            expect(onMouseDown).to.have.been.calledBefore(onMouseMove);
            expect(onMouseMove).to.have.been.calledBefore(onMouseUp);
        });
github wix-playground / stylable-components / test / components / global-event.spec.tsx View on Github external
it('should call new handler but not the old one', () =&gt; {
            const originalListener = sinon.spy();
            const newListener = sinon.spy();

            const fixture = clientRenderer.render(
                
            ).result as Fixture;
            fixture.setState({listener: newListener});

            windowStub.simulate('click');

            expect(originalListener).not.to.have.been.called;
            expect(newListener).to.have.been.calledOnce;
        });
github wix / wix-react-tools / test / react-component-features / disposable-feature.spec.tsx View on Github external
it('called on unmount', () =&gt; {
        const spy = sinon.spy();
        const {container} = clientRenderer.render(<div>);

        clientRenderer.render(<div></div>, container);
        expect(spy).to.have.callCount(0);

        clientRenderer.render(<div>, container);
        expect(spy).to.have.callCount(1);
    });
});</div></div>