Summary
valid-expect currently appears to treat expect.poll(...) and expect.element(...) as if poll / element were matchers.
However, in Vitest, these are expect APIs that start an assertion chain:
expect.poll(() => value).toBe(1)
expect.element(element).toBeInTheDocument()
In these chains, poll and element are not matchers. The actual matchers are toBe and toBeInTheDocument.
This can cause valid-expect to miss invalid expect.poll / expect.element usages.
Reproduction
Add the following cases to the invalid section of tests/valid-expect.test.ts:
{
code: 'expect.poll(() => value);',
errors: [{ messageId: 'matcherNotFound' }],
},
{
code: 'expect.element(element);',
errors: [{ messageId: 'matcherNotFound' }],
},
Then run:
pnpm test tests/valid-expect.test.ts
Currently, these cases fail because valid-expect reports no errors:
FAIL tests/valid-expect.test.ts > valid-expect > invalid > expect.poll(() => value);
FAIL tests/valid-expect.test.ts > valid-expect > invalid > expect.element(element);
AssertionError: Should have 1 error but had 0: []
0 !== 1
For comparison, the equivalent plain expect case is already reported correctly:
{
code: 'expect("something");',
errors: [{ messageId: 'matcherNotFound' }],
},
Expected behavior
valid-expect should treat expect.poll(...) and expect.element(...) as expect APIs, not as matchers.
For example:
expect.poll(() => value)
expect.element(element)
should be reported as matcherNotFound.
And these should remain valid:
await expect.poll(() => value).toBe(1)
await expect.element(element).toBeInTheDocument()
Summary
valid-expectcurrently appears to treatexpect.poll(...)andexpect.element(...)as ifpoll/elementwere matchers.However, in Vitest, these are expect APIs that start an assertion chain:
In these chains,
pollandelementare not matchers. The actual matchers aretoBeandtoBeInTheDocument.This can cause
valid-expectto miss invalidexpect.poll/expect.elementusages.Reproduction
Add the following cases to the
invalidsection oftests/valid-expect.test.ts:Then run:
pnpm test tests/valid-expect.test.tsCurrently, these cases fail because
valid-expectreports no errors:For comparison, the equivalent plain
expectcase is already reported correctly:Expected behavior
valid-expectshould treatexpect.poll(...)andexpect.element(...)as expect APIs, not as matchers.For example:
should be reported as
matcherNotFound.And these should remain valid: