Skip to content

Conversation

@StyleShit
Copy link
Contributor

Description

Resolves #8953

Flagging the callback happened inside the callback itself, which runs after the check whether it's poll or element, so I flagged it outside the callback

I want to add some tests. Saw that there are tests for poll-no-awaited, but I'm assuming that expect.element tests shouldn't be there and I wasn't sure how to test it. Would be glad to get some help here

@netlify
Copy link

netlify bot commented Nov 6, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6a5715f
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/690c79a8751faf00082d1608
😎 Deploy Preview https://deploy-preview-8954--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 project configuration.

@sheremet-va
Copy link
Member

The error is correct, just the message is wrong.

@StyleShit StyleShit changed the title fix: incorrect non-awaited expect.element() error fix: incorrect non-awaited expect.element() error message Nov 6, 2025
@sheremet-va
Copy link
Member

sheremet-va commented Nov 6, 2025

I don't see how this fixes the message. Please, add a test somewhere in test/browser, probably

@StyleShit
Copy link
Contributor Author

I don't see how this fixes the message

Determining the error message is based on a flag that's attached to the expect function reference (either expect.poll() or expect.element()).

What happened is that the flagging of expect.element() happens inside the function itself
(basically function expectElement() { addFlag(this, 'expect.element', true) }),
but the check against this flag runs before this function even runs, so it's not flagged yet.

add a test

Added. Took me some time to figure it out...

@StyleShit StyleShit changed the title fix: incorrect non-awaited expect.element() error message fix: incorrect error message for non-awaited expect.element() Nov 6, 2025
return result
}, processTimeoutOptions(options))

chai.util.flag(expectElement, '_poll.element', true)

Choose a reason for hiding this comment

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

Hi, new here :)
How does this ensures the right message?

@sheremet-va
Copy link
Member

but the check against this flag runs before this function even runs, so it's not flagged yet.

I see, the poll is not called at all if the function is not awaited, so the flag is never set

@sheremet-va sheremet-va merged commit 9638db0 into vitest-dev:main Nov 7, 2025
12 of 14 checks passed
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.

Incorrect error message in non-awaited expect.element() calls

3 participants