Skip to content

Commit 5532668

Browse files
committed
test: restore mocks in afterEach so a failure cannot leak
Each test that overrode `Platform.OS` or stubbed `console.warn` restored it on the last line, which never runs when an assertion throws. A single failing test left every later test in the file running as web, turning one real failure into a cascade of misleading ones. Matches the teardown FABExtended and Surface already use.
1 parent fe0bd30 commit 5532668

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

‎src/components/__tests__/Switch.test.tsx‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as React from 'react';
22
import { Platform } from 'react-native';
33

4-
import { describe, expect, it, jest } from '@jest/globals';
4+
import { afterEach, describe, expect, it, jest } from '@jest/globals';
55
import * as Reanimated from 'react-native-reanimated';
66

77
import { defaultThemes } from '../../core/theming';
@@ -12,6 +12,10 @@ import Switch from '../Switch/Switch';
1212
const animatedStyle = (testID: string) =>
1313
Reanimated.getAnimatedStyle(screen.getByTestId(testID));
1414

15+
afterEach(() => {
16+
jest.restoreAllMocks();
17+
});
18+
1519
describe('Switch render', () => {
1620
it('renders on', async () => {
1721
expect(
@@ -128,8 +132,6 @@ describe('Switch focus state', () => {
128132
await jest.runAllTimersAsync();
129133

130134
expect(animatedStyle('switch-focus-ring')).toMatchObject({ opacity: 0 });
131-
132-
jest.restoreAllMocks();
133135
});
134136

135137
it('shows the indicator for keyboard focus on web', async () => {
@@ -144,8 +146,6 @@ describe('Switch focus state', () => {
144146
await jest.runAllTimersAsync();
145147

146148
expect(animatedStyle('switch-focus-ring')).toMatchObject({ opacity: 1 });
147-
148-
jest.restoreAllMocks();
149149
});
150150

151151
it('clears the focus state when the switch stops being interactive', async () => {
@@ -185,8 +185,6 @@ describe('Switch operability', () => {
185185
expect(console.warn).toHaveBeenCalledWith(
186186
expect.stringContaining('onValueChange')
187187
);
188-
189-
jest.restoreAllMocks();
190188
});
191189

192190
it('is not focusable when it has no way to be operated', async () => {
@@ -196,8 +194,6 @@ describe('Switch operability', () => {
196194
await render(<Switch value />);
197195

198196
expect(screen.getByRole('switch')).toHaveProp('focusable', false);
199-
200-
jest.restoreAllMocks();
201197
});
202198

203199
it('announces a read-only switch without making it focusable', async () => {
@@ -221,8 +217,6 @@ describe('Switch operability', () => {
221217

222218
expect(control).toHaveProp('aria-readonly', true);
223219
expect(control).toBeEnabled();
224-
225-
jest.restoreAllMocks();
226220
});
227221

228222
it('does not announce a disabled switch as read-only', async () => {

0 commit comments

Comments
 (0)