8000 Enable Ton matchers in TypeScript when using `expect` from `@jest/globals` by EhsanMarufi · Pull Request #31 · ton-org/test-utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enable Ton matchers in TypeScript when using expect from @jest/globals #31

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

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

Conversation

EhsanMarufi
Copy link
@EhsanMarufi EhsanMarufi commented Jun 26, 2025

Ton custom matchers like toHaveTransaction were previously only available when using the global expect. This PR adds full TypeScript support for projects that import expect explicitly from @jest/globals.

Changes

  • Introduced a TonMatchers<R> interface to avoid duplication.
  • Augmented both:
    • Global jest.Matchers<R> (for traditional global usage).
    • Module @jest/expect's Matchers<R> (for explicit expect imports).
  • Ensured module augmentation is triggered by importing 'expect'.
  • No runtime changes; this is a pure typings enhancement.

Motivation

Modern Jest usage, especially in TypeScript projects, often relies on explicit imports like:

import { expect } from '@jest/globals';

Without this update, consumers lose type safety for Ton-specific matchers unless they use the global expect, which can lead to confusion or unnecessary workarounds.

Benefits

  • Enables proper typings for Ton matchers when using expect via @jest/globals.
  • Improves developer experience and consistency across test styles.
  • Avoids the need for local patches, manual module augmentation, or as any casts.

Checklist

  • All tests pass successfully (yarn test)
  • Code passes linting checks (yarn lint)

…est/globals

Ton custom matchers like `toHaveTransaction` were previously only available when using the global `expect`. This commit adds proper TypeScript support for projects that explicitly import `expect` from `@jest/globals`.

- Extracted shared matcher definitions into `TonMatchers<R>`.
- Augmented both global and module `Matchers` interfaces.

Enables type-safe use of Ton matchers with imported `expect`, improving developer experience and aligning with modern Jest usage patterns.
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
0