-
Notifications
You must be signed in to change notification settings - Fork 352
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
Upgrade @testing-library/user-event to v14 #1029
Conversation
Size Change: -16 B (0%) Total Size: 819 kB
ℹ️ View Unchanged
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1029 +/- ##
==========================================
+ Coverage 64.40% 66.12% +1.72%
==========================================
Files 427 429 +2
Lines 97246 97292 +46
Branches 6459 10034 +3575
==========================================
+ Hits 62628 64334 +1706
+ Misses 34618 32958 -1660
... and 109 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
@@ -9,6 +9,8 @@ import {StyleSheetTestUtils} from "aphrodite"; | |||
import jestSerializerHtml from "jest-serializer-html"; | |||
import {addSerializer} from "jest-specific-snapshot"; | |||
|
|||
import "@testing-library/jest-dom"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had sprinkled this in most test files. This makes starting a new test file just that little bit easier!
@@ -50,10 +50,9 @@ | |||
"@storybook/react-vite": "^7.6.17", | |||
"@swc-node/register": "^1.6.6", | |||
"@swc/core": "^1.3.68", | |||
"@testing-library/dom": "^8.11.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest-dom
already depends on this library and we never use it directly. So this avoids version mismatches (which I did hit while working on this PR) when we bump testing library versions.
import { | ||
screen, | ||
render, | ||
fireEvent, | ||
within, | ||
waitFor, | ||
} from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import {userEvent as userEventLib} from "@testing-library/user-event"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By aliasing the library import, we can avoid renaming all usages of the userEvent
throughout these tests. See the beforeEach()
below.
@@ -91,7 +97,7 @@ describe("math input integration", () => { | |||
).toBeInTheDocument(); | |||
}); | |||
|
|||
it("doesn't show the keypad initially", () => { | |||
it("doesn't show the keypad initially", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used some of the automation John figured out for migrating webapp and so there might be a few tests in this PR that are migrated to be async that don't actually call any async functions. In practice, this didn't seem to bother. I'm happy to roll back these if the reviewer has strong feelings. :)
@@ -260,13 +263,13 @@ describe("renderer", () => { | |||
}); | |||
|
|||
// Assert | |||
expect(sawDropdown2).toBeTrue(); | |||
expect(sawDropdown2).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started getting type errors on .toBeTrue()
and .toBeFalse()
. They appear to be from Jasmine and I'm unclear how this ever worked. 😦
const textboxes = screen.getAllByRole("textbox"); | ||
for (let i = 0; i < textboxes.length; i++) { | ||
await userEvent.type(textboxes[i], i.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just could not get .forEach()
to work with these async calls.
@@ -23,11 +22,29 @@ const mockSize = ( | |||
} | |||
}; | |||
|
|||
// The zoomable does some measuring after the initial render to determine what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I dug into these tests for the Zoomable, I discovered that they weren't really validating things correctly. I've fixed them up so that I think they are now correct and compatible with user-event@14
question: PerseusRenderer, | ||
correct: string, | ||
incorrect: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added names to the tuple items. Makes it a bit clearer.
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (979b477) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1029 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1029 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general pattern you've used here for user-event makes sense to me. An alternative for the beforeEach would be to change the render()
call to have a custom function that renders and returns a new userEvent object correctly-bound to the jest fake timers - but that's possibly more work? I'm defer to others on the review of the specifics of the tests. Thanks for the user-event upgrade!
1d5e2b5
to
2dcd058
Compare
… typescript types for custom matches
2dcd058
to
eb81fae
Compare
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/perseus-editor@4.3.0 ### Minor Changes - [#1025](#1025) [`5ec2bb71`](5ec2bb7) Thanks [@nishasy](https://github.com/nishasy)! - Create InteractiveGraphSettings to be used in InteractiveGraphEditor in place of GraphSettings ### Patch Changes - [#1029](#1029) [`17d05e8e`](17d05e8) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Migrate to @testing-library/user-event v14. - [#1022](#1022) [`b2649c32`](b2649c3) Thanks [@nishasy](https://github.com/nishasy)! - Correct type for `valid` prop from `boolean` to `boolean | string` - [#1024](#1024) [`0c9fe476`](0c9fe47) Thanks [@nishasy](https://github.com/nishasy)! - Add labels to input fields in GraphSettings + tests. - Updated dependencies \[[`17d05e8e`](17d05e8), [`7e4a65f0`](7e4a65f)]: - @khanacademy/math-input@17.2.1 - @khanacademy/perseus@19.6.2 ## @khanacademy/perseus-dev-ui@1.1.5 ### Patch Changes - [#1029](#1029) [`17d05e8e`](17d05e8) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Migrate to @testing-library/user-event v14. - [#1012](#1012) [`7e4a65f0`](7e4a65f) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Change Vite config so it can be re-used by Storybook - Updated dependencies \[[`17d05e8e`](17d05e8), [`7e4a65f0`](7e4a65f)]: - @khanacademy/math-input@17.2.1 ## @khanacademy/math-input@17.2.1 ### Patch Changes - [#1029](#1029) [`17d05e8e`](17d05e8) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Migrate to @testing-library/user-event v14. - [#1012](#1012) [`7e4a65f0`](7e4a65f) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix handling of "Fractions" keypad in the keypad tab bar icon component ## @khanacademy/perseus@19.6.2 ### Patch Changes - [#1029](#1029) [`17d05e8e`](17d05e8) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Migrate to @testing-library/user-event v14. - Updated dependencies \[[`17d05e8e`](17d05e8), [`7e4a65f0`](7e4a65f)]: - @khanacademy/math-input@17.2.1 Author: khan-actions-bot Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ⏭ Publish npm snapshot, ✅ Extract i18n strings (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ gerald, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x) Pull Request URL: #1030
Summary:
This PR upgrades the user-event library to v14. This contains a similar set of changes to what is contained in Khan/webapp#20109. It prepares the way for Khan Academy to move to React v18.
In short:
userEvent
library are now treated as async (prefixed withawait
)Issue: LC-1753
Test plan:
yarn test
👍yarn lint
👍