Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): better local test context support (#1805)
* feat(types): better local test context support * feat(types): fix beforeEach and afterEach * test: add unit test for local context
- Loading branch information
1 parent
18e0bec
commit 426503c
Showing
4 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
describe('local test context works with explicit type', () => { | ||
interface LocalTestContext { | ||
foo: string | ||
} | ||
beforeEach<LocalTestContext>((context) => { | ||
context.foo = 'foo' | ||
}) | ||
it<LocalTestContext>('works with explicit type', (context) => { | ||
expect(context.foo).toBe('foo') | ||
}) | ||
it.todo.skip<LocalTestContext>('is chainable with explicit type', (context) => { | ||
expect(context.foo).toBe('foo') | ||
}) | ||
}) | ||
|
||
describe('local test context works with implicit type', () => { | ||
interface LocalTestContext { | ||
bar: string | ||
} | ||
beforeEach((context: LocalTestContext) => { | ||
context.bar = 'bar' | ||
}) | ||
it('works with implicit type', (context: LocalTestContext) => { | ||
expect(context.bar).toBe('bar') | ||
}) | ||
it.only('is chainable with implicit type', (context: LocalTestContext) => { | ||
expect(context.bar).toBe('bar') | ||
}) | ||
}) |