You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`expect.poll` makes every assertion asynchronous, so do not forget to await it otherwise you might get unhandled promise rejections.
85
+
`expect.poll` makes every assertion asynchronous, so you need to await it. Since Vitest 2.2, if you forget to await it, the test will fail with a warning to do so.
If the assertion is not awaited, then you will have a false-positive test that will pass every time. To make sure that assertions are actually called, you may use [`expect.assertions(number)`](#expect-assertions).
1188
+
1189
+
Since Vitest 2.2, if a method is not awaited, Vitest will show a warning at the end of the test. In Vitest 3, the test will be marked as "failed" if the assertion is not awaited.
1188
1190
:::
1189
1191
1190
1192
## rejects
@@ -1214,6 +1216,8 @@ test('buyApples throws an error when no id provided', async () => {
1214
1216
1215
1217
:::warning
1216
1218
If the assertion is not awaited, then you will have a false-positive test that will pass every time. To make sure that assertions were actually called, you can use [`expect.assertions(number)`](#expect-assertions).
1219
+
1220
+
Since Vitest 2.2, if a method is not awaited, Vitest will show a warning at the end of the test. In Vitest 3, the test will be marked as "failed" if the assertion is not awaited.
`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`,
107
+
)
108
+
throwcopyStackTrace(error,STACK_TRACE_ERROR)
109
+
}
110
+
})
111
+
letresultPromise: Promise<void>|undefined
112
+
// only .then is enough to check awaited, but we type this as `Promise<void>` in global types
expect(stderr).toContain('The call was not awaited. This method is asynchronous and must be awaited; otherwise, the call will not start to avoid unhandled rejections.')
exports[`should fail node-browser-context.test.ts > node-browser-context.test.ts 1`] = `"Error: @vitest/browser/context can be imported only inside the Browser Mode. Your test is running in forks pool. Make sure your regular tests are excluded from the "test.include" glob pattern."`;
"Error: expect.poll(assertion).toBe() was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
65
+
AssertionError: expected 3 to be 4 // Object.is equality
66
+
Error: expect.poll(assertion).toBe() was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
67
+
Error: expect.poll(assertion).toBe() was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
68
+
Error: expect.poll(assertion).not.toBe() was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
69
+
Error: expect.poll(assertion).toBe() was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:"
"Promise returned by \`expect(actual).resolves.toBe(expected)\` was not awaited. Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. Please remember to await the assertion.
99
+
at <rootDir>/base.test.js:5:33",
100
+
"Promise returned by \`expect(actual).rejects.toBe(expected)\` was not awaited. Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. Please remember to await the assertion.
101
+
at <rootDir>/base.test.js:10:32",
102
+
"Promise returned by \`expect(actual).resolves.toBe(expected)\` was not awaited. Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. Please remember to await the assertion.
103
+
at <rootDir>/base.test.js:9:33",
104
+
"Promise returned by \`expect(actual).resolves.toBe(expected)\` was not awaited. Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. Please remember to await the assertion.
105
+
at <rootDir>/base.test.js:14:33",
106
+
"Promise returned by \`expect(actual).toMatchFileSnapshot(expected)\` was not awaited. Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. Please remember to await the assertion.
107
+
at <rootDir>/base.test.js:19:17",
108
+
]
109
+
`)
110
+
})
111
+
112
+
it('prints a warning if the assertion is not awaited in the browser mode',async()=>{
113
+
const{ stderr }=awaitrunInlineTests({
114
+
'./vitest.config.js': {
115
+
test: {
116
+
browser: {
117
+
enabled: true,
118
+
name: 'chromium',
119
+
provider: 'playwright',
120
+
headless: true,
121
+
},
122
+
},
123
+
},
124
+
'base.test.js': ts`
125
+
import { expect, test } from 'vitest';
126
+
127
+
test('single not awaited', () => {
128
+
expect(Promise.resolve(1)).resolves.toBe(1)
129
+
})
130
+
`,
131
+
})
132
+
expect(stderr).toContain('Promise returned by \`expect(actual).resolves.toBe(expected)\` was not awaited')
0 commit comments