Skip to content

Handle forgotten await#43

Merged
calebeby merged 2 commits intomainfrom
catch-forgot-await
Feb 26, 2021
Merged

Handle forgotten await#43
calebeby merged 2 commits intomainfrom
catch-forgot-await

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