Skip to content

VirtualConsolePrinter.readAsString()

David Ortner edited this page Jan 21, 2025 · 6 revisions

Adds an event listener.

Signature

readAsString(logLevel?: VirtualConsoleLogLevelEnum): string;

Parameters

Parameter Type Default Description
logLevel? VirtualConsoleLogLevelEnum VirtualConsoleLogLevelEnum.log This log level or greater (e.g. "log" as level will output "log", "info", "warn" and "error")

Returns

string

Example

import { Window, VirtualConsoleLogLevelEnum } from "happy-dom";

const window = new Window();

window.console.log("Test", { test: true });

const log = window.happyDOM.virtualConsolePrinter.readAsString(
   VirtualConsoleLogLevelEnum.log
);

// Will output 'Test {"test": true}' to the NodeJS console
global.console.log(log);
Clone this wiki locally