mirror of
https://github.com/johndoe6345789/docker-swarm-termina.git
synced 2026-04-24 13:45:01 +00:00
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:
@@ -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>,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user