Skip to content

Commit e7a984f

Browse files
fix(tests): add Platform.OS cleanup to EditDisplayNameSheet test
Add proper Platform.OS restoration in afterEach hook to prevent test pollution between tests. Also use Object.defineProperty instead of direct assignment for Platform.OS mutations, which is the recommended pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent daa2c1b commit e7a984f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

__tests__/components/sheets/EditDisplayNameSheet.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ const mockTheme = {
8181
glassBorder: 'rgba(255,255,255,0.3)',
8282
};
8383

84+
// Store original Platform.OS for restoration
85+
const originalPlatformOS = Platform.OS;
86+
8487
// =============================================================================
8588
// Tests
8689
// =============================================================================
@@ -89,6 +92,13 @@ describe('EditDisplayNameSheet', () => {
8992
jest.clearAllMocks();
9093
});
9194

95+
afterEach(() => {
96+
// Restore Platform.OS after each test to prevent test pollution
97+
Object.defineProperty(Platform, 'OS', {
98+
get: () => originalPlatformOS,
99+
});
100+
});
101+
92102
// ---------------------------------------------------------------------------
93103
// Rendering Tests
94104
// ---------------------------------------------------------------------------
@@ -425,7 +435,7 @@ describe('EditDisplayNameSheet', () => {
425435
});
426436

427437
it('shows confirmation dialog on web when closing with unsaved changes', () => {
428-
Platform.OS = 'web';
438+
Object.defineProperty(Platform, 'OS', { get: () => 'web' });
429439
// Mock window.confirm for web platform
430440
const mockConfirm = jest.fn().mockReturnValue(false);
431441
global.window = { confirm: mockConfirm } as any;
@@ -458,7 +468,7 @@ describe('EditDisplayNameSheet', () => {
458468
});
459469

460470
it('shows alert on native when closing with unsaved changes', () => {
461-
Platform.OS = 'ios';
471+
Object.defineProperty(Platform, 'OS', { get: () => 'ios' });
462472
const mockAlert = jest.spyOn(Alert, 'alert');
463473
const mockOnSave = jest.fn();
464474
const mockOnClose = jest.fn();

0 commit comments

Comments
 (0)