From 9718fcca89cd0c1ef1b9c88ba5795c9cd58ddcca Mon Sep 17 00:00:00 2001 From: Jeremy Wiebe Date: Mon, 9 Sep 2024 15:56:49 -0700 Subject: [PATCH] Switch from using useRef() to createRef() (#1603) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: I noticed a test that was jumping through hoops with spies in order to manage a ref in tests. Using `React.createRef()` is simpler and avoids needing to mock a hook. Issue: "none" ## Test plan: `yarn test` ✅ Author: jeremywiebe Reviewers: aemandine, #perseus, nishasy Required Reviewers: Approved By: aemandine Checks: ❌ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), 🚫 Upload Coverage, ✅ gerald, ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Cypress (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), 🚫 Check for .changeset entries for all changed files (ubuntu-latest, 20.x), 🚫 Jest Coverage (ubuntu-latest, 20.x), 🚫 Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/1603 --- .../__tests__/interactive-graph-editor.test.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/perseus-editor/src/widgets/__tests__/interactive-graph-editor.test.tsx b/packages/perseus-editor/src/widgets/__tests__/interactive-graph-editor.test.tsx index 8de1b9fc3f..dba66beab9 100644 --- a/packages/perseus-editor/src/widgets/__tests__/interactive-graph-editor.test.tsx +++ b/packages/perseus-editor/src/widgets/__tests__/interactive-graph-editor.test.tsx @@ -574,10 +574,7 @@ describe("InteractiveGraphEditor", () => { test("getSaveWarnings returns an error when the graph is invalid", async () => { // Arrange - jest.spyOn(React, "useRef").mockReturnValue({ - current: null, - }); - const ref = React.useRef(null); + const ref = React.createRef(); // Act render( @@ -611,10 +608,7 @@ describe("InteractiveGraphEditor", () => { test("getSaveWarnings is empty if there are no errors", async () => { // Arrange - jest.spyOn(React, "useRef").mockReturnValue({ - current: null, - }); - const ref = React.useRef(null); + const ref = React.createRef(); // Act render(