Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot with ComponentDidCatch #6707

Closed
mitsuishihidemi opened this issue Jul 17, 2018 · 2 comments
Closed

Snapshot with ComponentDidCatch #6707

mitsuishihidemi opened this issue Jul 17, 2018 · 2 comments

Comments

@mitsuishihidemi
Copy link

mitsuishihidemi commented Jul 17, 2018

馃挰 Questions and Help

Hi,

I am testing a HOC with componentDidCatch with Snapshot, and it is working but it displays an annoying message on my terminal. Do you know how can I hide that?

with-error.js

import React from 'react';
import { wrapDisplayName, setDisplayName } from 'recompose';

const ErrorPage = () => <h1>There is an error</h1>;

export default hasError => BaseComponent => {
    class WithErrorBoundary extends React.Component {
        state = { error: false };

        componentWillReceiveProps(nextProps) {
            if (hasError(nextProps) && !this.state.error) {
                this.setState({ error: true });
            }
        }

        componentDidCatch() {
            this.setState({ error: true });
        }

        render() {
            return this.state.error ? <ErrorPage /> : <BaseComponent {...this.props} />;
        }
    }

    return setDisplayName(wrapDisplayName(BaseComponent, 'ErrorCatcher'))(WithErrorBoundary);
};

with.error.test.js

it('should display the error page if it catchs an error', () => {
        const Component = withError()(() => {
            throw new Error('Error');
        });
        const subject = renderer
            .create(
                <Component />
            )
            .toJSON();
        expect(subject).toMatchSnapshot();
    });

The error message
screen shot 2018-07-17 at 12 52 17

I found this issue, but even with enzyme I got the same error.
enzymejs/enzyme#1255

react: ^16.3.2
jest: ^22.4.2

Thanks,

Please note that this issue tracker is not a help form and this issue will be closed.

For questions or help please see:

@rickhanlonii
Copy link
Member

You could override console.error and test for that error message

Please note that this issue tracker is not a help form and this issue will be closed.

We recommend using our discord channel or StackOverflow where there is an active jestjs tag for questions

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants