Skip to content

feat(mock): mock and doMock support typed first arg#418

Merged
fi3ework merged 2 commits intomainfrom
type-au
Jul 24, 2025
Merged

feat(mock): mock and doMock support typed first arg#418
fi3ework merged 2 commits intomainfrom
type-au

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Jul 24, 2025

Summary

rs.mock and rs.doMock also support passing a Promise<T> as the first parameter, and use the type T as the return value type of the second factory function after awaiting (Promise<T>). This provides better type hints in IDEs and type validation for the factory function's return value. Passing Promise<T> only enhances type hints and has no impact on the module mocking capabilities.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings July 24, 2025 07:12
@netlify
Copy link
Copy Markdown

netlify bot commented Jul 24, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit f987913
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6881dfeadf82aa0008bdc0b3
😎 Deploy Preview https://deploy-preview-418--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the type system for rs.mock and rs.doMock methods by allowing a Promise<T> as the first parameter to provide better TypeScript type inference and IDE support. The enhancement extracts the type T from the Promise and uses it to type the factory function's return value as Partial<T>.

  • Updated type signatures to accept string | Promise<T> as the first parameter
  • Added comprehensive test coverage for the new typed argument feature
  • Updated documentation in both English and Chinese to explain the new functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/types/mock.ts Updated type definitions for mock methods to support Promise as first argument and improved type safety
tests/mock/tests/mockTypedArg.test.ts Added comprehensive tests demonstrating the new typed argument functionality
tests/mock/src/*.ts Added explicit type annotations to exported constants for better type inference
website/docs/*/api/rstest/mockModules.mdx Updated documentation to explain the new Promise parameter support

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@fi3ework fi3ework requested a review from 9aoy July 24, 2025 07:26
@fi3ework fi3ework merged commit 6e81e17 into main Jul 24, 2025
16 checks passed
@fi3ework fi3ework deleted the type-au branch July 24, 2025 07:43
@9aoy 9aoy mentioned this pull request Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants