Silence console warnings in frontend tests

Suppress expected console output during tests:
- layout.test.tsx: DOM nesting warnings (html in div) expected when testing Next.js RootLayout
- useInteractiveTerminal.test.tsx: terminal initialization logs
- useTerminalModalState.test.tsx: fallback mode warnings

https://claude.ai/code/session_014uQFZGsQRXtUAcxgzDkSaW
This commit is contained in:
Claude
2026-02-01 17:25:52 +00:00
parent 06649e4f23
commit 72369eddce
3 changed files with 46 additions and 0 deletions

View File

@@ -2,6 +2,24 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import RootLayout, { metadata } from '../layout';
// Suppress console.error for DOM nesting warnings in tests
// (html cannot be child of div - expected when testing Next.js RootLayout)
const originalConsoleError = console.error;
beforeAll(() => {
console.error = jest.fn((...args) => {
const message = args.map(arg => String(arg)).join(' ');
// Suppress DOM nesting warnings that occur when testing RootLayout
if (message.includes('cannot be a child of') || message.includes('hydration error')) {
return;
}
originalConsoleError.apply(console, args);
});
});
afterAll(() => {
console.error = originalConsoleError;
});
// Mock the ThemeProvider and Providers
jest.mock('@/lib/theme', () => ({
ThemeProvider: ({ children }: { children: React.ReactNode }) => <div data-testid="theme-provider">{children}</div>,

View File

@@ -1,6 +1,23 @@
import { renderHook, act } from '@testing-library/react';
import { useInteractiveTerminal } from '../useInteractiveTerminal';
// Suppress console output during tests (terminal initialization logs)
const originalConsoleLog = console.log;
const originalConsoleWarn = console.warn;
const originalConsoleError = console.error;
beforeAll(() => {
console.log = jest.fn();
console.warn = jest.fn();
console.error = jest.fn();
});
afterAll(() => {
console.log = originalConsoleLog;
console.warn = originalConsoleWarn;
console.error = originalConsoleError;
});
// Mock socket.io-client
const mockSocket = {
on: jest.fn(),

View File

@@ -1,6 +1,17 @@
import { renderHook, act } from '@testing-library/react';
import { useTerminalModalState } from '../useTerminalModalState';
// Suppress console.warn during tests (fallback mode warnings are expected)
const originalConsoleWarn = console.warn;
beforeAll(() => {
console.warn = jest.fn();
});
afterAll(() => {
console.warn = originalConsoleWarn;
});
// Mock MUI hooks
jest.mock('@mui/material', () => ({
...jest.requireActual('@mui/material'),