Skip to content

node-text-codec-globals

Restores Node’s TextEncoder and TextDecoder on a test environment’s global object that lacks them.

vitest’s jsdom environment copies both from Node, but jest-environment-jsdom does not, so under Jest an @mnaoumov/obsidian-lib plugin’s onload threw ReferenceError: TextEncoder is not defined. The generic restoreNodeWebGlobals from @mnaoumov/typescript-test-toolkit does not cover these two names.

Function Description
restoreNodeTextCodecGlobals Defines each of TextEncoder and TextDecoder on the target from node:util, unless the target already has it.
Variable Description
NODE_TEXT_CODEC_GLOBALS The text codec classes this module restores, by global name.