Skip to content

fix: handle expect.any separately from Chai any flag#925

Merged
veritem merged 1 commit into
vitest-dev:mainfrom
nami8824:fix-valid-expect-any-chai-flag
Jul 6, 2026
Merged

fix: handle expect.any separately from Chai any flag#925
veritem merged 1 commit into
vitest-dev:mainfrom
nami8824:fix-valid-expect-any-chai-flag

Conversation

@nami8824

@nami8824 nami8824 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #924

Summary

This fixes a valid-expect regression introduced after Chai-style expect chain support in #920.

expect.any(...) was accidentally classified as Chai's .any flag because any is also a Chai chain property. As a result, valid-expect reported Expect has an unknown modifier.

This PR restores the pre-#920 behavior for called expect.any(...), while keeping uncalled .any in Chai chains working:

expect.any(String) // expect.any(...)

expect(value).to.have.any.keys('a', 'b') // Chai `.any` flag

A broader parser change to distinguish asymmetric matcher factories from assertion matcher calls can be handled separately if needed.

chasset added a commit to univ-lehavre/atlas that referenced this pull request Jul 6, 2026
…-expect) (#559)

## Contexte

La PR Dependabot #555 (`all-minor-patch`, 23 bumps) échoue au job
**Lint** à
cause d'un seul bump : `@vitest/eslint-plugin` **1.6.20 → 1.6.21**.

La 1.6.21 (« Support Chai-style expect chains ») confond le matcher
asymétrique
`expect.any(...)` avec le flag Chai `any`. La règle
`vitest/valid-expect` le
signale alors à tort **« unknown modifier »** sur le motif canonique :

```ts
expect(tls.connect).toHaveBeenCalledWith(
  expect.objectContaining({ ... }),
  expect.any(Function),
);
```

Constaté sur
[packages/net/src/diagnostics.spec.ts](packages/net/src/diagnostics.spec.ts)
(3 assertions **correctes**).

## Amont

- Bug ouvert : vitest-dev/eslint-plugin-vitest#924 (« `valid-expect`
forbids
  `expect.any(type)` »).
- Correctif proposé : vitest-dev/eslint-plugin-vitest#925 — **non mergé,
non
  publié** (1.6.21 reste la dernière version).

## Correctif

Override scopé dans `pnpm-workspace.yaml` plafonnant le plugin à
`<1.6.21` :

```yaml
"@vitest/eslint-plugin@>=1.6.21": "1.6.20"
```

On préfère épingler un outil de lint dev-only régressé plutôt que tordre
des
tests corrects. **À lever** dès qu'une version corrigée (1.6.22+) sort.

Effet sur le lock : purge des `@typescript-eslint/*@8.61.0` orphelines
(tirées
uniquement par le plugin en 1.6.21).

## Suite

Cette PR débloque #555 : une fois mergée, rebaser #555 sur `main` — le
bump
vitest-plugin y devient inopérant (l'override le ramène à 1.6.20) et le
job Lint
passera.

## Validation locale

- `pnpm lint` : 64/64 packages OK
- `pnpm install --frozen-lockfile` : lock cohérent
- `prettier --check` : OK
@veritem veritem merged commit 3415709 into vitest-dev:main Jul 6, 2026
5 checks passed
@Janpot Janpot mentioned this pull request Jul 7, 2026
1 task
@gijs-martens

Copy link
Copy Markdown

@veritem could this please be released as a fix straight away? This regression is rather painful.

@ahaverbuch

Copy link
Copy Markdown

Confirming this fixes a real-world regression we hit in @vitest/eslint-plugin@1.6.21: valid-expect flagged expect.any(...) / expect.objectContaining(...) nested inside toHaveBeenCalledWith(...) as Expect has an unknown modifier in a large monorepo, breaking CI across dozens of otherwise-correct test files. We ended up excluding 1.6.21 in our semver range ("1.6.20 || ^1.6.22") until this ships in a release. Thanks for the quick fix!

@shimscho

shimscho commented Jul 8, 2026

Copy link
Copy Markdown

please release 1.6.22.. it is such a pain

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.

valid-expect forbids expect.any(type)

5 participants