Use expect 28 style typescript module augmentation #483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
This adds a
types
export for the package, using jest 28's recommended way to augmentexpect
: https://jestjs.io/blog/2022/04/25/jest-28#expectThis might be a breaking change for users on jest 27 or below and using typescript.
Why:
I want to update
@storybook/expect
to use jest 28, but currently, due to the typescript changes in jest 28, the types from jest-dom are broken.I took a look at a few issues in this repo, including #426, #314, and #457, and I think I'm not alone in having issues with jest 28 and types.
How:
This augments the
expect
package, using the types from definitely-typed (instead of trying to move them into this package for now).Checklist:
I'm opening this up for discussion. I tested this approach out in my own project, and it works correctly when I also add an
import '@testing-library/jest-dom';
statement in@storybook/expect
. I wanted to see if the maintainers of this repo would consider making a breaking change to support jest 28+, or if you have any other ideas of how to handle types for projects which aren't usingjest
globals, but are usingexpect
directly.Note: I also had to tweak the eslint config a little bit, so that the
@typescript-eslint
rules stopped failing and would let the precommit hook succeed. Buuuut, it looks like that's failing CI. Maybe a maintainer can getmain
working correctly with eslint, and I can rebase this on top?