From 9833ce96cd9129b8e6b99debe2bf84771058cfa7 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 18 Jun 2024 07:15:53 -0400 Subject: [PATCH] test: remove test-util --- src/components/AllRead.test.tsx | 11 +++++++++-- src/components/test-utils.ts | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 src/components/test-utils.ts diff --git a/src/components/AllRead.test.tsx b/src/components/AllRead.test.tsx index d2ec0f3aa..da53fc8cd 100644 --- a/src/components/AllRead.test.tsx +++ b/src/components/AllRead.test.tsx @@ -1,11 +1,18 @@ import { render } from '@testing-library/react'; import { AllRead } from './AllRead'; -import { mockMathRandom } from './test-utils'; describe('components/AllRead.tsx', () => { + const originalMathRandom = Math.random; + // The read emoji randomly rotates, but then the snapshots would never match // Have to make it consistent so the emojis are always the same - mockMathRandom(0.1); + beforeEach(() => { + global.Math.random = jest.fn(() => 0.1); + }); + + afterEach(() => { + global.Math.random = originalMathRandom; + }); it('should render itself & its children', () => { const tree = render(); diff --git a/src/components/test-utils.ts b/src/components/test-utils.ts deleted file mode 100644 index af8bbcd42..000000000 --- a/src/components/test-utils.ts +++ /dev/null @@ -1,11 +0,0 @@ -const originalMathRandom = Math.random; - -export const mockMathRandom = (mockValue: number) => { - beforeEach(() => { - global.Math.random = jest.fn(() => mockValue); - }); - - afterEach(() => { - global.Math.random = originalMathRandom; - }); -};