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

fix: force cast await to proper type #1293

Merged
merged 7 commits into from
Jan 26, 2023
Merged

fix: force cast await to proper type #1293

merged 7 commits into from
Jan 26, 2023

Conversation

mdjastrzebski
Copy link
Member

@mdjastrzebski mdjastrzebski commented Jan 26, 2023

Summary

Resolve typing issues with act by allowing to invoke both act() and await act(). React act has uses function overloading which is hard to work with, so I've resorted to casting.

Dropping support for mock act and increasing peer dep req to React 16.8 (earliest version to expose act in Test Renderer). I think we can avoid calling this a breaking change, as we already specified minimal RN version of 0.59, which uses React 16.8.3 (see here)

Resolves #1276
Resolves #1207

Test plan

Typecheck runs fine.

src/act.ts Outdated Show resolved Hide resolved
src/__tests__/act.test.tsx Outdated Show resolved Hide resolved

function withGlobalActEnvironment(actImplementation: Act) {
return (callback: Parameters<Act>[0]) => {
function withGlobalActEnvironment(actImplementation: ReactAct) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it even useful to pass it actImplementation as a param?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmmm, good question, we've got our code from RTL and just sprinkled types and eslint ignores over it.
I guess it's easier to keep it in sync with their implmentation.

package.json Show resolved Hide resolved
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Left one comment, other than that LGTM

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Base: 95.19% // Head: 95.98% // Increases project coverage by +0.78% 🎉

Coverage data is based on head (2e375eb) compared to base (0af7211).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1293      +/-   ##
==========================================
+ Coverage   95.19%   95.98%   +0.78%     
==========================================
  Files          47       47              
  Lines        3249     3240       -9     
  Branches      489      489              
==========================================
+ Hits         3093     3110      +17     
+ Misses        156      130      -26     
Impacted Files Coverage Δ
src/act.ts 96.51% <100.00%> (+27.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mdjastrzebski mdjastrzebski merged commit 4decd45 into main Jan 26, 2023
@mdjastrzebski mdjastrzebski deleted the fix/act-await-type branch January 26, 2023 21:28
Copy link

@trajano trajano left a comment

Choose a reason for hiding this comment

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

lgtm

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.

Typescript act() got warning 'await' has no effect on the type of this expression. Typing of act broken
4 participants