Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest --env=jsdom TypeError: TextDecoder is not a constructor #10

Closed
lidel opened this issue Nov 9, 2020 · 5 comments
Closed

jest --env=jsdom TypeError: TextDecoder is not a constructor #10

lidel opened this issue Nov 9, 2020 · 5 comments

Comments

@lidel
Copy link
Collaborator

lidel commented Nov 9, 2020

jest with --env=jsdom fails with TypeError: TextDecoder is not a constructor

@Gozala did not dig into it, but I assume this is a bug: it is fair to expect people use js-multiaddr (which depends on web-encoding) in apps tested with jest.

That's what we do in ipfs-webui – see below.

How to reproduce

Having below in multibase/src/util.js causes jest-based tests to fail in ipfs-webui:

const { TextEncoder, TextDecoder } = require('web-encoding')
const textDecoder = new TextDecoder()     
 FAIL  src/bundles/analytics.test.js
  ● Test suite failed to run

    TypeError: TextDecoder is not a constructor

    > 1 | import multiaddr from 'multiaddr'
        | ^
      2 | // @ts-ignore
      3 | import HttpClient from 'ipfs-http-client'
      4 | // @ts-ignore

      at Object.<anonymous> (node_modules/uint8arrays/node_modules/multibase/src/util.js:6:21)
      at Object.<anonymous> (node_modules/uint8arrays/node_modules/multibase/src/base.js:4:24)
      at Object.<anonymous> (node_modules/uint8arrays/node_modules/multibase/src/constants.js:5:14)
      at Object.<anonymous> (node_modules/uint8arrays/to-string.js:3:19)
@Gozala
Copy link
Owner

Gozala commented Nov 9, 2020

@lidel this seems like the same issue as #1 (comment) do you mind checking if the same workaround works in this context as well ?

@dannyhchan
Copy link

Getting error when using it in the latest create web app with node v15.4.0. Does anyone know how to resolve this?

textDecoder-error

System:
OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla)
CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Binaries:
Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 7.0.15 - ~/.nvm/versions/node/v15.4.0/bin/npm

@ghost
Copy link

ghost commented Apr 20, 2021

Getting error when using it in the latest create web app with node v15.4.0. Does anyone know how to resolve this?

textDecoder-error

System:
OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla)
CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Binaries:
Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 7.0.15 - ~/.nvm/versions/node/v15.4.0/bin/npm

hi, have you solved it?

@dannyhchan
Copy link

@mandyJiai no, I was not able to solve it. It seems that the issue was caused by using the ipfs-http-client library. Instead of using that library, I switched to using ipfs-api which still worked for my use case.

@Gozala
Copy link
Owner

Gozala commented Apr 20, 2021

@mandyJiai @dannyhchan as described in in this comment #1 (comment) issue is caused by jest and jsdom combination and not this library. It can be fixed by updating jest.

@Gozala Gozala closed this as completed Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants