console
An object that writes messages to the Console in the Tests tab.
Declaration
consoleOverview
Messages a script writes with console appear in the Console section of the response inspector's Tests tab, in the order they were written, with a badge for their level. A link at the end of each line shows the line of the script that wrote it.
const body = relay.response.json();
console.log("Received", body.items.length, "items");
console.warn("Deprecated endpoint:", relay.response.headers.get("Deprecation"));
console.log(body.items[0]);Relay writes its own warnings to the Console too, such as when a script sets an environment variable while no environment is active.
Topics
Writing messages
log(…values)
console.log(...values: any[]): voidWrites values to the Console.
info(…values)
console.info(...values: any[]): voidWrites values to the Console as information.
warn(…values)
console.warn(...values: any[]): voidWrites values to the Console as a warning.
error(…values)
console.error(...values: any[]): voidWrites values to the Console as an error.
debug(…values)
console.debug(...values: any[]): voidWrites values to the Console as debugging output. console.trace() does the same.
table(…values), dir(…values)
console.table(...values: any[]): void
console.dir(...values: any[]): voidWrite values to the Console, as log() does.
assert(condition, …values)
console.assert(condition: any, ...values: any[]): voidWrites "Assertion failed" and the values as an error when condition is falsy. It doesn't fail a test or record an assertion.
Ignored methods
clear(), time(), timeEnd(), group(), groupEnd()
console.clear()
console.time(label)
console.timeEnd(label)
console.group(label)
console.groupEnd()Do nothing, so scripts that call them still run.
Discussion
Values are joined with spaces. Objects and arrays are written as JSON, and an error is written as its message. Double-click a long message to show all of it.
Relay keeps up to 500 lines from each phase and notes when it drops more. A message longer than 10,000 characters is truncated. The Console is kept with the response in history, and Copy Results in the Tests tab copies it with the test results.
See Also
- Testing responses: Check responses automatically with tests and assertions.
- test: A function that runs a named check and records whether it passed.