Skip to content

feat(expect): toContain can handle classList and Node.contains#4239

Merged
sheremet-va merged 6 commits intovitest-dev:mainfrom
sheremet-va:feat/toContain-dom
Nov 15, 2023
Merged

feat(expect): toContain can handle classList and Node.contains#4239
sheremet-va merged 6 commits intovitest-dev:mainfrom
sheremet-va:feat/toContain-dom

Conversation

@sheremet-va
Copy link
Member

Description

Fixes #2395

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 Oct 4, 2023

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit 960321e
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/6554f6c284c5c30007aaf0ed
😎 Deploy Preview https://deploy-preview-4239--fastidious-cascaron-4ded94.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.

@ferdynator
Copy link

Any updates on this? toContains was working with classLists just fine in jest and this is breaking tests on migrating away to vitest

@sheremet-va sheremet-va merged commit ce84f06 into vitest-dev:main Nov 15, 2023
@sheremet-va sheremet-va deleted the feat/toContain-dom branch November 15, 2023 17:39
@charkour
Copy link

charkour commented Dec 8, 2023

This update also broke my tests in https://github.com/charkour/zundo. I'm not sure why that's the case yet.

}
// make "actual" indexable to have compatibility with jest
if (actual != null && typeof actual !== 'string')
utils.flag(this, 'object', Array.from(actual as Iterable<unknown>))
Copy link

Choose a reason for hiding this comment

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

I think this Array.from is causing bugs. If actual is an object, then it will always return an empty array which is an issue.

Copy link

Choose a reason for hiding this comment

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

Ah, I found that this is expected and I should instead use toMatchObject rather than toContain.

https://stackoverflow.com/questions/47754777/how-can-i-test-for-object-keys-and-values-equality-using-jest

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.

Support toContain with element.classList

3 participants