When writing tests, use the appropriate testing utilities and ensure proper test isolation.

For testing warning behaviors:

For testing sequential or asynchronous actions:

Always clean up after tests that use mocks:

// Bad: No cleanup after mocking
console.error = jest.fn();
// Test code...
// Missing cleanup!

// Good: Proper cleanup
const originalConsoleError = console.error;
console.error = jest.fn();
// Test code...
console.error = originalConsoleError; // Or use console.error.mockRestore();

// Better: Use afterEach for guaranteed cleanup
beforeEach(() => {
  jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
  console.error.mockRestore();
});

Failing to clean up mocks can silently break subsequent tests by interfering with their assertions, making test failures difficult to debug.