[]previous and next page

setWarningListener

Sends every later warning to next instead of console.warn, for devtools and test helpers (@shadow-js/testing) that collect warnings.

Sends every later warning to next instead of console.warn, for devtools and test helpers (@shadow-js/testing) that collect warnings. Deduplication still applies: the listener receives the first warning of each code only. Warnings exist in development builds only.

Import#

ts
import { setWarningListener } from "@shadow-js/core/extend";

Signature#

ts
function setWarningListener(next: WarningListener | undefined): WarningListener | undefined

Parameters#

Name Description
next The listener to install. Undefined restores the default, console.warn.

Returns#

The listener that was installed before, or undefined when it was the default, so the caller can restore it.

Examples#

ts
import { type MessageCode, setWarningListener } from "@shadow-js/core/extend";

const codes: MessageCode[] = [];
const previous = setWarningListener((code) => {
  codes.push(code);
});
// ... run the code under test, then:
setWarningListener(previous);