@bufbuild/jest-environment-jsdom
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@bufbuild/jest-environment-jsdom

An extension of jest-environment-jsdom with support for the Encoding API.

Background

When using the test framework Jest for a web application, you will likely use the "jsdom" test environment to make the DOM available in tests. But if your code or one of your dependencies relies on the encoding API, you will see the following error when running tests:

ReferenceError: TextEncoder is not defined

This package adds the Node.js built-in classes TextEncoder and TextDecoder to the jsdom test environment to work around the problem. If you can spare the time, consider helping out with the upstream issue in the jsdom project.

Usage

Install the package (note that jest-environment-jsdom is still required as a peer dependency):

npm install --save-dev jest-environment-jsdom @bufbuild/jest-environment-jsdom

Update the testEnvironment property of your Jest config like so:

import type { Config } from 'jest';

const config: Config = {
- testEnvironment: 'jsdom',
+ testEnvironment: '@bufbuild/jest-environment-jsdom',
...
};

Readme

Keywords

none

Package Sidebar

Install

npm i @bufbuild/jest-environment-jsdom

Weekly Downloads

1,121

Version

0.1.1

License

Apache-2.0

Unpacked Size

6.29 kB

Total Files

7

Last publish

Collaborators

  • srikrsna-buf
  • jdailey_buf
  • sayers-buf
  • psachs-buf
  • bufbot
  • tstamm-buf
  • bufdev