A fixture named `task` breaks `expect` from the test context
Maintainers usually reply within 1 day
@hrishikeshpathak1009 is already working on this.
Since Nov 10, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript, vite
- Domain
- testing
Research direction
Start in packages/vitest/src/runtime/runners/test.ts, in extendTaskContext, where the expect and bench getters are described. Reproduce the fixture collision with the supplied Vitest example, then inspect the context setup to identify the test instance it was created for. Done means the getters use that test instance and the regression cases for task, expect, and bench behave correctly.
Written by the indexing model from the issue text.
Description
A fixture named task replaces context.task. The expect from the test context is created lazily from context.task, so after fixtures run it gets the fixture value instead of the test:
- a failed
expect.softpasses toMatchInlineSnapshotthrowsTypeError: Cannot read properties of undefined (reading 'filepath')
The imported expect is not affected.
Reproduction
Vitest 5.1.0:
import { test as baseTest } from 'vitest'
const test = baseTest.extend('task', () => ({ title: 'write docs', done: false }))
test('soft assertion fails', ({ task, expect }) => {
// passes
expect.soft(task.done).toBe(true)
})
test('inline snapshot passes', ({ task, expect }) => {
// TypeError: Cannot read properties of undefined (reading 'filepath')
expect(task.title).toMatchInlineSnapshot(`"write docs"`)
})
The expect and bench getters in extendTaskContext (packages/vitest/src/runtime/runners/test.ts) read context.task when they are first accessed. They should use the test that the context was created for.
Related: a fixture named expect or bench throws TypeError: Cannot set property expect of function() {...}, because both are getters without a setter. The types accept both fixtures.
- Dominant language
- TypeScript
- Stars
- 17.4k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 148
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitest-dev/vitest
-
approved documentation
Difficulty 1/5 Under an hour Newbie friendliness 89/100
vitest-dev/vitest#12015 · 4 comments ·
Maintainers usually reply within 1 day
-
docs: say that `vi.stubEnv` changes only `import.meta.env` in Browser ModeMay be free again A pull request for this issue was closed without being merged. Opendocumentation p1-chore
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
vitest-dev/vitest#11971 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vitest-dev/vitest#11941 · 2 comments ·
Maintainers usually reply within 1 day
-
`%%` in a `test.each` / `describe.each` / `test.for` title consumes a parameterMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vitest-dev/vitest#11913 · 1 comment ·
Maintainers usually reply within 1 day
-
Docs: importOriginal return type is missing PromisePossibly taken @ragib-mrb claimed this 6 days ago. Opendocumentation
Difficulty 1/5 Under an hour Newbie friendliness 94/100
vitest-dev/vitest#11894 · 1 comment ·
Maintainers usually reply within 1 day
All issues in vitest-dev/vitest
Similar issues
-
approved check:passed streams:remove
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Monthly Not a priority
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Expensify/App#107229 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
GitTools/actions#2297 · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
hiero-ledger/hiero-sdk-js#4793 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/vscode-cosmosdb#3594 · 1 comment ·
Maintainers usually reply within 1 day