Skip to content

Conversation

@sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Mar 11, 2025

Description

I was writing tests and notice that it would be nice to have this during the test in case users provide text.extend overrides and can't use test.skipIf() during collection:

test('some test', { custom, skip } => {
  skip(custom === 'value', 'not supported')
})

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:.

@netlify
Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 3fbd625
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67d042fb176fae00089b2825
😎 Deploy Preview https://deploy-preview-7659--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.

@sheremet-va sheremet-va changed the title feat(vitest): allow conditional context.skip(boolean) feat(vitest): allow conditional context.skip(boolean) Mar 11, 2025
@sheremet-va sheremet-va added this to the 3.1.0 milestone Mar 11, 2025
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

So is this any different from following:

test('skipped test', (context) => {
-  Math.random() < 0.5 && context.skip('optional message')
+  context.skip(Math.random() < 0.5, 'optional message')
  // Test skipped, no error
  assert.equal(Math.sqrt(4), 3)
})

@sheremet-va
Copy link
Member Author

So is this any different from following:

It is not different, just a syntactic sugar. See playwright for example: https://playwright.dev/docs/api/class-testinfo#test-info-skip-2

We already support test.skipIf instead of asking people to use if(condition) { test }, so I don't see any issue here 😄

@AriPerkkio
Copy link
Member

If playwright has it, sounds good to me.

We already support test.skipIf instead of asking people to use if(condition) { test }, so I don't see any issue here 😄

That would not be collected as skipped test though, so not equivalent.

Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Yeah, I've seen on playwright before and I thought why not 👍

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.

3 participants