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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use string argument on 'with event' #67

Open
salomvary opened this issue Sep 24, 2020 · 2 comments
Open

Can't use string argument on 'with event' #67

salomvary opened this issue Sep 24, 2020 · 2 comments

Comments

@salomvary
Copy link

I was trying to use the shallow renderer to invoke a custom event handler with a string argument, eg. aliensLanded('thousand'). Tried this:

        it('calls events with string event parameter', () => {
            renderer.render(<ClickableComponent />);

            expect(renderer, 'with event', 'aliensLanded', 'thousand', 'to have rendered',
                <div>
                    <span className="main-click">Main clicked 1000</span>
                </div>);
        });

which did not work:

     UnexpectedError: 
Unknown assertion 'thousand', did you mean: 'on'

I understand telling the argument from the next assertion can be tricky if it's a string and the documentation clearly states that the argument has to be an object but custom "events" with non-object arguments are a real thing in my experience.

@salomvary
Copy link
Author

Seems like using more than one argument is not supported either. How about adding <ReactElement> with event <string> <array> <assertion?> where array would be the arguments array of whatever types and not the first argument? For example:

        it('calls events with string event parameter', () => {
            renderer.render(<ClickableComponent />);

            expect(renderer, 'with event', 'aliensLanded', ['thousand', 'the second argument'], 'to have rendered',
                <div>
                    <span className="main-click">Main clicked 1000</span>
                </div>);
        });

would call aliensLanded('thousand', 'the second argument')

@bruderstein
Copy link
Owner

That sounds like a really good idea to cover those cases. Should be trivial-ish to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants