GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: throw an error and a warning if `.poll`, `.element`, `.rejects`/`.resolves`, and `locator.*` weren't awaited by sheremet-va · Pull Request #6877 · vitest-dev/vitest

Conversation

@sheremet-va

@sheremet-va sheremet-va commented Nov 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description

If expect.poll().to* or expect.element().to* is not awaited, the test will now fail. The stack trace leads to the line where it's called. The callback to .poll will never be called to avoid unhandled rejections.

Screenshot 2024-11-07 at 15 20 44

If expect.rejects/expect.resolves was not awaited, Vitest will print a warning:

Screenshot 2024-11-08 at 14 31 48

If async locator.* methods are not awaited, Vitest will fail the test. The RPC will never be called to avoid unhandled rejections:

Screenshot 2024-11-08 at 14 34 01

TODO:

  • Test
  • Docs update

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Smrtnyk reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@sheremet-va

sheremet-va commented Nov 7, 2024

Copy link
Copy Markdown
Member Author

@hi-ogawa this was pretty easy to do 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netlify

netlify Bot commented Nov 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 6a2b63d
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/672e151f1026f60008316111
😎 Deploy Preview https://deploy-preview-6877--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Smrtnyk

Smrtnyk commented Nov 7, 2024

Copy link
Copy Markdown

I was bitten by this many times 😓
good stuff to have this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheremet-va

sheremet-va commented Nov 7, 2024

Copy link
Copy Markdown
Member Author

@hi-ogawa @AriPerkkio should we do the same with .resolves and .rejects? 🤔

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheremet-va
sheremet-va marked this pull request as ready for review November 7, 2024 14:17
@sheremet-va
sheremet-va requested review from AriPerkkio and hi-ogawa November 7, 2024 14:17
hi-ogawa
hi-ogawa previously approved these changes Nov 8, 2024
View reviewed changes

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me 👍
One caveat is that it's not a genuine promise tracker, so something like these get through.

test('repro', async () => {
  myPollWrapper();

  Promise.all([
    expect.poll(() => 3).toBe(4),
    expect.poll(() => 3).toBe(4),
  ]);
})

async function myPollWrapper() {
  await expect.poll(() => 3).toBe(4);
}

But these are only false-negative of some edge cases and I don't see any false-positive, so this should be a nice improvement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
AriPerkkio
AriPerkkio previously approved these changes Nov 8, 2024
View reviewed changes

@AriPerkkio AriPerkkio left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good! Showing the erroneous line is really nice dx improvement. 💯

should we do the same with .resolves and .rejects?

Sure why not. I'm not familiar with internals of expect, but could this be done on any higher level instead of patching all matchers?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hi-ogawa

hi-ogawa commented Nov 8, 2024

Copy link
Copy Markdown
Collaborator

should we do the same with .resolves and .rejects? 🤔

Does this means we remove recordAsyncExpect trick for auto await? I would prefer the change as it would be more well-defined behaviors for users. I guess technically that would be breaking change though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheremet-va

sheremet-va commented Nov 8, 2024

Copy link
Copy Markdown
Member Author

should we do the same with .resolves and .rejects? 🤔

Does this means we remove recordAsyncExpect trick for auto await? I would prefer the change as it would be more well-defined behaviors for users. I guess technically that would be breaking change though.

Hm, I am not sure what is better 🤔 I like to be stricter, but I don't know if we can enforce it now 🤔 The expect.resolves basically implicitly becomes expect.soft.resolves right now, and it's documented

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheremet-va

sheremet-va commented Nov 8, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I think maybe we should also throw an error or show a warning if locator methods were not awaited:

getByRole('button').click()
expect(button).toHaveText('123')

React shows a warning if React.act wasn't called, and we can maybe do the same instead of failing the test 🤔 (But since we know what test caused it, we can also force it to fail which might be better)

What do you think?

Smrtnyk reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheremet-va
sheremet-va dismissed stale reviews from AriPerkkio and hi-ogawa via 15a6965 November 8, 2024 12:25
@sheremet-va
sheremet-va force-pushed the fix/check-poll-awaited branch from a6a4fb5 to 15a6965 Compare November 8, 2024 12:25
@sheremet-va sheremet-va changed the title fix: throw an error if .poll or .element wasn't awaited fix: throw an error and a warning if .poll, .element wasn't awaited Nov 8, 2024
@sheremet-va sheremet-va changed the title fix: throw an error and a warning if .poll, .element wasn't awaited fix: throw an error and a warning if .poll, .element, .rejects/.resolves, and locator.* weren't awaited Nov 8, 2024
sheremet-va added 13 commits November 12, 2024 17:15
@sheremet-va
fix: throw an error if .poll or .element wasn't awaited
7ccf858
@sheremet-va
chore: more promises
959d362
@sheremet-va
fix: run all onTestFinished/onTestFailed hooks even if one fails
0cbfaf4
@sheremet-va
docs: mention the test will fail if poll is not awaited
4ae82aa
@sheremet-va
test: add failing tests
b53d9ef
@sheremet-va
fix: use .not in the error message if it was used
f831179
@sheremet-va
feat: show a warning if .promise/.rejects was not awaited
9c81186
@sheremet-va
chore: cleanup
dcd5ea9
@sheremet-va
fix: correct stack trace in the browser, throw if locator.* was not a…
7f349d2
…waited
@sheremet-va
docs: add docs about warnings and errors if async is not awaited
bb508f4
@sheremet-va
test: add a button
f213d5c
@sheremet-va
test: fix line numbers
dd068fd
@sheremet-va
chore: use resolve from pathe
cc14a69
@sheremet-va
sheremet-va force-pushed the fix/check-poll-awaited branch from da62143 to cc14a69 Compare November 12, 2024 16:16
sheremet-va added 3 commits November 13, 2024 12:25
@sheremet-va
fix: don't call a promise if it wasn't awaited
9c12714
@sheremet-va
test: fix tests
a80b56b
@sheremet-va
test: fix safari
269a4b7
@sheremet-va
sheremet-va merged commit 93b67c2 into vitest-dev:main Nov 13, 2024
@sheremet-va
sheremet-va deleted the fix/check-poll-awaited branch November 13, 2024 12:19
renovate Bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 13, 2024
@renovate
chore(deps): update dependency vitest to v2.1.5
916c364
##### [v2.1.5](https://github.com/vitest-dev/vitest/releases/tag/v2.1.5)

#####    🚀 Features

-   **experimental**: Expose vite on the test project as a separate field  -  by [@sheremet-va](https://github.com/sheremet-va) [<samp>(bcc59)</samp>](vitest-dev/vitest@bcc59088)

#####    🐞 Bug Fixes

-   `dangerouslyIgnoreUnhandledErrors` without base reporter  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6808 [<samp>(0bf0a)</samp>](vitest-dev/vitest@0bf0ab00)
-   Capture `unhandledRejection` even when base reporter is not used  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6812 [<samp>(8878b)</samp>](vitest-dev/vitest@8878b04d)
-   Don't change the working directory when loading workspace projects  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6811 [<samp>(f0aea)</samp>](vitest-dev/vitest@f0aeaca8)
-   Remove `sequence.concurrent` from the `RuntimeConfig` type  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6880 [<samp>(6af73)</samp>](vitest-dev/vitest@6af73d93)
-   Stop the runner before restarting, restart on workspace config change  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6859 [<samp>(b01df)</samp>](vitest-dev/vitest@b01df47d)
-   Don't rerun on Esc or Ctrl-C during watch filter  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6895 [<samp>(98f76)</samp>](vitest-dev/vitest@98f76ea7)
-   Print ssrTransform error  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6885 [<samp>(4c96c)</samp>](vitest-dev/vitest@4c96cce7)
-   Throw an error and a warning if `.poll`, `.element`, `.rejects`/`.resolves`, and `locator.*` weren't awaited  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6877 [<samp>(93b67)</samp>](vitest-dev/vitest@93b67c24)
-   **browser**:
    -   Don't process the default css styles  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6861 [<samp>(0d67f)</samp>](vitest-dev/vitest@0d67f04b)
    -   Support non US key input  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6873 [<samp>(5969d)</samp>](vitest-dev/vitest@5969d8da)
    -   Stop the browser rpc when the pool is closed  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6858 [<samp>(9a0c9)</samp>](vitest-dev/vitest@9a0c93d7)
    -   Init browsers eagerly when tests are running  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6876 [<samp>(417bd)</samp>](vitest-dev/vitest@417bdb42)
-   **coverage**:
    -   Report uncovered files when re-run by `enter` or `'a'`  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6848 [<samp>(487c8)</samp>](vitest-dev/vitest@487c80ae)
-   **ui**:
    -   Remove crossorigin attributes for same origin assets  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6883 [<samp>(6e793)</samp>](vitest-dev/vitest@6e793c64)
-   **vite-node**:
    -   Improve esm check to decide external  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6816 [<samp>(7e1fa)</samp>](vitest-dev/vitest@7e1faf3d)
    -   Top-level throw in module is not reported properly  -  by [@vanaigr](https://github.com/vanaigr) and [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6840 [<samp>(cf0cb)</samp>](vitest-dev/vitest@cf0cbf6a)
-   **vitest**:
    -   Use fetch() implementation from happy-dom  -  by [@capricorn86](https://github.com/capricorn86) in vitest-dev/vitest#6879 [<samp>(3c56f)</samp>](vitest-dev/vitest@3c56feb4)

#####    🏎 Performance

-   Limit workspace project concurrency to available cores  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6869 [<samp>(f4c04)</samp>](vitest-dev/vitest@f4c04ab6)

#####     [View changes on GitHub](vitest-dev/vitest@v2.1.4...v2.1.5)
renovate Bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 13, 2024
@renovate
chore(deps): update dependency vitest to v2.1.5
58ba87f
##### [v2.1.5](https://github.com/vitest-dev/vitest/releases/tag/v2.1.5)

#####    🚀 Features

-   **experimental**: Expose vite on the test project as a separate field  -  by [@sheremet-va](https://github.com/sheremet-va) [<samp>(bcc59)</samp>](vitest-dev/vitest@bcc59088)

#####    🐞 Bug Fixes

-   `dangerouslyIgnoreUnhandledErrors` without base reporter  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6808 [<samp>(0bf0a)</samp>](vitest-dev/vitest@0bf0ab00)
-   Capture `unhandledRejection` even when base reporter is not used  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6812 [<samp>(8878b)</samp>](vitest-dev/vitest@8878b04d)
-   Don't change the working directory when loading workspace projects  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6811 [<samp>(f0aea)</samp>](vitest-dev/vitest@f0aeaca8)
-   Remove `sequence.concurrent` from the `RuntimeConfig` type  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6880 [<samp>(6af73)</samp>](vitest-dev/vitest@6af73d93)
-   Stop the runner before restarting, restart on workspace config change  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6859 [<samp>(b01df)</samp>](vitest-dev/vitest@b01df47d)
-   Don't rerun on Esc or Ctrl-C during watch filter  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6895 [<samp>(98f76)</samp>](vitest-dev/vitest@98f76ea7)
-   Print ssrTransform error  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6885 [<samp>(4c96c)</samp>](vitest-dev/vitest@4c96cce7)
-   Throw an error and a warning if `.poll`, `.element`, `.rejects`/`.resolves`, and `locator.*` weren't awaited  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6877 [<samp>(93b67)</samp>](vitest-dev/vitest@93b67c24)
-   **browser**:
    -   Don't process the default css styles  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6861 [<samp>(0d67f)</samp>](vitest-dev/vitest@0d67f04b)
    -   Support non US key input  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6873 [<samp>(5969d)</samp>](vitest-dev/vitest@5969d8da)
    -   Stop the browser rpc when the pool is closed  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6858 [<samp>(9a0c9)</samp>](vitest-dev/vitest@9a0c93d7)
    -   Init browsers eagerly when tests are running  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6876 [<samp>(417bd)</samp>](vitest-dev/vitest@417bdb42)
-   **coverage**:
    -   Report uncovered files when re-run by `enter` or `'a'`  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6848 [<samp>(487c8)</samp>](vitest-dev/vitest@487c80ae)
-   **ui**:
    -   Remove crossorigin attributes for same origin assets  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6883 [<samp>(6e793)</samp>](vitest-dev/vitest@6e793c64)
-   **vite-node**:
    -   Improve esm check to decide external  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6816 [<samp>(7e1fa)</samp>](vitest-dev/vitest@7e1faf3d)
    -   Top-level throw in module is not reported properly  -  by [@vanaigr](https://github.com/vanaigr) and [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6840 [<samp>(cf0cb)</samp>](vitest-dev/vitest@cf0cbf6a)
-   **vitest**:
    -   Use fetch() implementation from happy-dom  -  by [@capricorn86](https://github.com/capricorn86) in vitest-dev/vitest#6879 [<samp>(3c56f)</samp>](vitest-dev/vitest@3c56feb4)

#####    🏎 Performance

-   Limit workspace project concurrency to available cores  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6869 [<samp>(f4c04)</samp>](vitest-dev/vitest@f4c04ab6)

#####     [View changes on GitHub](vitest-dev/vitest@v2.1.4...v2.1.5)
@renovate renovate Bot mentioned this pull request Nov 26, 2024
chore(deps): update root (major) - autoclosed productdevbookcom/nuxt-bundle-template#39
Closed
1 task
@sheremet-va sheremet-va mentioned this pull request Feb 23, 2026
await expect.poll + finally fails by "not awaited" detection #9724
Closed
6 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Jun 12, 2026
plan-agent-ui-data-v1: 天道 agent 驱动 client UI 面板(双向 UI-as-Data 管道) Kizunad/Bong#522
Merged
hanzo-dev pushed a commit to hanzoai/vitest that referenced this pull request Sep 9, 2026
@sheremet-va
fix: throw an error and a warning if .poll, .element, .rejects/…
21cdabe
…`.resolves`, and `locator.*` weren't awaited (vitest-dev#6877)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hi-ogawa hi-ogawa hi-ogawa left review comments
@AriPerkkio AriPerkkio AriPerkkio left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@sheremet-va @Smrtnyk @hi-ogawa @AriPerkkio
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.