Optional test #10502
RobinTail
started this conversation in
Show and tell
Optional test
#10502
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Following the #4920 I'd like to share a code sample I found out recently for implementing an optional test that depends on external resource having questionable availability and uses the built-in skipping mechanism instead of just passing with a message that can be lost in logs. This may also be useful for flaky tests. The idea is to wrap the flaky part into the
test.extend()and use the context-levelskip()method inside the actual test.I found this approach cleaner than async
describeandtest.skipIf().The default reporter handles it nicely:
And the summary emphasizes the skipped test:
References:
test.extend— https://vitest.dev/api/test.html#test-extendcontext.skip— https://vitest.dev/guide/test-context.html#skipBeta Was this translation helpful? Give feedback.
All reactions