React-tooltip: Unit Testing

Created on 9 Jul 2018  路  3Comments  路  Source: wwayne/react-tooltip

Is it possible to unit test this component?
Seeing as it uses document.querySelectorAll, I haven't been able to figure out how to test this tooltips using jest and enzyme.

All 3 comments

I used this code and it worked, but this doesn't seem like a very nice way of doing this... I'd appreciate if anyone knew better ways.

    it('should render a proper popover when element clicked', (done) => {
         const wrapper = mountWithTheme(
            <Box>
                <Button
                    data-popover=''
                    data-for={props.id} />

                <ReactTooltip
                    {...props}
                    hover={hover} />
            </Box>
        );

        expect(wrapper.find('.show').length).toBe(0);

        document.body.innerHTML = wrapper.getDOMNode().innerHTML;

        setTimeout(() => {
            document.body.firstChild.dispatchEvent(new Event('click'));
            wrapper.update();

            const popover = wrapper.find('.show');

            expect(popover.length).toBe(1);
            expect(popover.text()).toBe(props.children);

            document.body.innerHTML = '';

            done();
        }, 200);
    });

Some example to make above testing using react-testing-library????

Hi guys, facing the same issue testing this. Any idea?

Was this page helpful?
0 / 5 - 0 ratings