-
-
Notifications
You must be signed in to change notification settings - Fork 216
VirtualConsolePrinter.addEventListener()
David Ortner edited this page Jan 21, 2025
·
4 revisions
Adds an event listener.
addEventListener(eventType: 'print' | 'clear', listener: (event: Event) => void): void;
Parameter | Type | Description |
---|---|---|
eventType | "print" | "clear" | Event type. |
listener | (event: Event) => void): void | Listener to add. |
void
import { Window } from 'happy-dom';
const window = new Window();
window.happyDOM.virtualConsolePrinter.addEventListener('print', () => {
const log = window.happyDOM.virtualConsolePrinter.readAsString();
// Will output 'Test {"test": true}' to the NodeJS console
global.console.log(log);
});
window.console.log('Test', { test: true });
import { Window } from 'happy-dom';
const window = new Window();
window.happyDOM.virtualConsolePrinter.addEventListener('clear', () => {
// Will clear the NodeJS log
global.console.clear();
});
window.console.clear();
Help Packages