Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

web-encoding package causes problems with jest in env=node and env=jsdom #66

@moodysalem

Description

@moodysalem

Describe the bug
When running the test in jest (with either env=jsdom or env=node setting) the TextDecoder or TextEncoder is not a constructor error makes it impossible to write unit tests using this module

To Reproduce
This simple test and code fails to run in jest
code:
https://github.com/Uniswap/uniswap-interface/blob/0aabf4856e6e90041caf4233db4b7defb01574a2/src/utils/contenthashToUri.ts
test:
https://github.com/Uniswap/uniswap-interface/blob/0aabf4856e6e90041caf4233db4b7defb01574a2/src/utils/contenthashToUri.test.skip.ts

error:
TypeError: TextDecoder is not a constructor


    TypeError: TextDecoder is not a constructor

    > 1 | import CID from 'cids'
        | ^
      2 | import { getCodec, rmPrefix } from 'multicodec'
      3 | import { decode, toB58String } from 'multihashes'
      4 |

      at Object.<anonymous> (node_modules/multibase/src/util.js:6:21)
      at Object.<anonymous> (node_modules/multibase/src/base.js:4:24)
      at Object.<anonymous> (node_modules/multibase/src/constants.js:5:14)
      at Object.<anonymous> (node_modules/multibase/src/index.js:9:19)
      at Object.<anonymous> (node_modules/multihashes/src/index.js:10:19)
      at Object.<anonymous> (node_modules/cids/src/index.js:3:12)
      at Object.<anonymous> (src/utils/contenthashToUri.ts:1:1)
      at Object.<anonymous> (src/utils/contenthashToUri.test.ts:1:1)

Expected behavior
TextDecoder from the environment (specifically, global for node and window for jsdom jest setting) is successfully loaded

Screenshots
image

Desktop (please complete the following information):

  • OS: MacOS

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions