How to use the test-drive-react.ClientRenderer 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 / 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-playground / stylable-components / test / components / context-provider.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; clientRenderer.cleanup());

    it('renders as a div by default', () =&gt; {
        const {select} = clientRenderer.render();

        expect(select(automationId)).to.be.instanceof(HTMLDivElement);
    });

    it('allows specifying the root tag element type', () =&gt; {
        const {select} = clientRenderer.render();

        expect(select(automationId)).to.be.instanceof(HTMLParagraphElement);
    });

    it('renders provided children', () =&gt; {
        const {select} = clientRenderer.render(
github wix-playground / stylable-components / test / components / checkbox.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();

    afterEach(() =&gt; {
        clientRenderer.cleanup();
    });

    describe('Component / Demo test', () =&gt; {
        it('Basic demo', async () =&gt; {
            const {driver, waitForDom} = clientRenderer.render().withDriver(CheckBoxDemoDriver);

            const checkbox = driver.basicDemo.checkbox;
            const button = driver.basicDemo.button;

            await waitForDom(() =&gt; {
                expect(checkbox.root, 'basic root').to.be.present();
                expect(checkbox.isChecked(), 'expected checkbox to be unchecked').to.equal(false);
                expect(checkbox.children[0], 'basic label').to.have.text(demoCheckBoxText);
github wix / wix-react-tools / test / react-component-features / disposable-feature.spec.tsx View on Github external
describe.assuming(inBrowser(), 'only in browser')("disposable decorator", () =&gt; {
    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; runInContext(devMode.OFF, () =&gt; clientRenderer.cleanup()));

    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>
github wix-playground / stylable-components / test / components / drop-down.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; clientRenderer.cleanup());

    const items = [
        {label: 'Muffins'},
        {label: 'Pancakes'},
        {label: 'Waffles'}
    ];

    it('renders a dropdown, opens it with a click, selects an item', async () =&gt; {
        const {select, waitForDom} = clientRenderer.render();

        await waitForDom(() =&gt; expect(select(dropDownDemo, list)).to.be.absent());

        simulate.click(select(dropDownDemo, input));

        await waitForDom(() =&gt; expect(select(dropDownDemo, list)).to.be.present());
github wix-playground / stylable-components / test / components / tree-view.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; clientRenderer.cleanup());

    const sampleItem = {label: 'label'};
    const nestedItem: TreeItemData = treeData[0].children![1];

    const allNodesLabels: string[] = getAllNodeLabels(treeData);

    it('renders a tree view with a few children', async () =&gt; {
        const {driver: treeViewDemo, waitForDom} = clientRenderer.render(
            
        ).withDriver(TreeViewDemoDriver);

        const {treeView} = treeViewDemo;

        await waitForDom(() =&gt; expect(treeView.root, 'demo not present').to.be.present());
github wix-playground / stylable-components / test / components / tooltip.spec.tsx View on Github external
describe(`render with ${position} position`, () => {
        const clientRenderer = new ClientRenderer();
        afterEach(() => clientRenderer.cleanup());

        let driver: any;
        let tooltipBounds: any;
        let anchorBounds: any;
        let tailBounds: any;
        beforeEach(() => {
            driver = renderWithProps(clientRenderer, {position});
            tooltipBounds = driver.tooltipBounds;
            anchorBounds = driver.anchorBounds;
            tailBounds = driver.tailBounds;
        });

        if (expectations.positionTop) {
            it('should be on the top', () => {
                equal(anchorBounds.top, tooltipBounds.top + tooltipBounds.height - tooltipBounds.marginTop);
github wix-playground / stylable-components / test / components / heading.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; clientRenderer.cleanup())

    it('outputs an <h1> element by default', async () =&gt; {
        const { select, waitForDom } =
            clientRenderer.render(Test heading);

        await waitForDom(() =&gt; {
            const heading = select('HEADING');
            expect(heading).to.be.present();
            expect(heading).to.be.instanceOf(HTMLHeadingElement);
            expect(heading!.tagName).to.equal('H1');
            expect(heading).to.contain.text('Test heading');
        });
    });

    ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'].forEach((headingType: any) =&gt; {</h1>
github wix / wix-react-tools / test / react-component-features / properties-feature.spec.tsx View on Github external
describe.assuming(inBrowser(), 'only in browser')('react root wrapper', () =&gt; {

    const clientRenderer = new ClientRenderer();
    afterEach(() =&gt; runInContext(devMode.OFF, () =&gt; clientRenderer.cleanup()));

    it("works with empty SFC", () =&gt; {
        const Comp = properties(() =&gt; <div data-automation-id="Root">);

        const {select} = clientRenderer.render();

        expect(select('Root')).to.be.ok;
    });

    it("works with empty class", () =&gt; {
        @properties
        class Comp extends React.Component {
            render() {
                return <div data-automation-id="Root">;
            }</div></div>
github wix-playground / stylable-components / test / components / slider.spec.tsx View on Github external
describe('', () =&gt; {
    const clientRenderer = new ClientRenderer();

    beforeEach(() =&gt; {
        environment = new WindowStub();
    });

    afterEach(() =&gt; {
        environment.sandbox.restore();
    });
    afterEach(() =&gt; {
        clientRenderer.cleanup();
    });

    describe('without any arguments', () =&gt; {
        let select: (automationId: string) =&gt; HTMLElement | null;
        let waitForDom: (expectation: () =&gt; void) =&gt; Promise;