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

Handle forgotten await #43

Merged
merged 2 commits into from
Feb 26, 2021
Merged

Handle forgotten await #43

merged 2 commits into from
Feb 26, 2021

Conversation

calebeby
Copy link
Member

Provide a helpful message if the user forgets to use await,

For example, if a user forgets to use await in the jest-dom assertion:

test(
  'example',
  withBrowser(async ({ screen, utils }) => {
    await utils.injectHTML('<button>Hi</button>');
    const button = await screen.getByText(/hi/i);
    expect(button).toBeVisible();
  }),
);

Then a useful error message is produced:

Cannot execute assertion toBeVisible after test finishes. Did you forget to await?

  103 |     await utils.injectHTML('<button>Hi</button>');
  104 |     const button = await screen.getByText(/hi/i);
> 105 |     expect(button).toBeVisible();
      |                    ^
  106 |   }),
  107 | );
  108 |

This is also handled for utility functions, user methods, and Testing Library queries.

Closes #30

Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Co-authored-by: Gerardo Rodriguez <gerardo@cloudfour.com>
@calebeby calebeby merged commit beb1914 into main Feb 26, 2021
@calebeby calebeby deleted the catch-forgot-await branch February 26, 2021 23:03
@github-actions github-actions bot mentioned this pull request Feb 26, 2021
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

Successfully merging this pull request may close these issues.

Try to catch errors where people forget to await
2 participants