Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to type t.context by extending module interface #3362

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

acro5piano
Copy link

Thank you for the great tool.

Summary

This Pull Request introduces a new AvaContext interface that can be augmented by library users. By allowing developers to declare custom fields in their test context, this change provides greater flexibility and type safety when writing tests in TypeScript.

Details of Changes

  • Added AvaContext Interface
    • Introduced a new AvaContext interface
    • Updated TestFn to default its generic Context to AvaContext
  • Updated corresponding docs

Library users can now directly extend the AvaContext interface to add custom properties in tests, which could be impressive when using shared context:

declare module 'ava' {
  interface AvaContext {
    foo: string;
  }
}

Difference between TestFn

There is already a guide to type t.context:

const test = anyTest as TestFn<{foo: string}>;

This PR provides another method to type the context without creating a new variable, which make users ease to use context values.

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.

1 participant