Skip to content

Commit

Permalink
Switch from using useRef() to createRef() (#1603)
Browse files Browse the repository at this point in the history
## 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: #1603
  • Loading branch information
jeremywiebe authored Sep 9, 2024
1 parent 7ddeca4 commit 9718fcc
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<InteractiveGraphEditor>(null);
const ref = React.createRef<InteractiveGraphEditor>();

// Act
render(
Expand Down Expand Up @@ -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<InteractiveGraphEditor>(null);
const ref = React.createRef<InteractiveGraphEditor>();

// Act
render(
Expand Down

0 comments on commit 9718fcc

Please sign in to comment.