Jest: Jest test report TypeError: StringDecoder is not a constructor

Created on 12 Dec 2018  路  2Comments  路  Source: facebook/jest

馃悰 Bug Report

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

      at Request.Object.<anonymous>.Readable.setEncoding (node_modules/readable-stream/lib/_stream_readable.js:326:39)
      at rawBody (node_modules/fastify/lib/contentTypeParser.js:116:9)
      at ContentTypeParser.Object.<anonymous>.ContentTypeParser.run (node_modules/fastify/lib/contentTypeParser.js:72:7)
      at handleRequest (node_modules/fastify/lib/handleRequest.js:35:33)
      at onRunMiddlewares (node_modules/fastify/fastify.js:446:5)
      at middlewareCallback (node_modules/fastify/fastify.js:434:7)
      at Object.routeHandler [as handler] (node_modules/fastify/fastify.js:286:7)

 RUNS  src/stream.test.ts
/Users/timothy/Workspace/timothy/test/node_modules/readable-stream/lib/_stream_readable.js:327
  this._readableState.decoder = new StringDecoder(enc);
                                ^

TypeError: StringDecoder is not a constructor
    at Request.Object.<anonymous>.Readable.setEncoding (/Users/timothy/Workspace/timothy/test/node_modules/readable-stream/lib/_stream_readable.js:327:33)
    at rawBody (/Users/timothy/Workspace/timothy/test/node_modules/fastify/lib/contentTypeParser.js:116:9)
    at ContentTypeParser.Object.<anonymous>.ContentTypeParser.run (/Users/timothy/Workspace/timothy/test/node_modules/fastify/lib/contentTypeParser.js:72:7)
    at handleRequest (/Users/timothy/Workspace/timothy/test/node_modules/fastify/lib/handleRequest.js:35:33)
    at onRunMiddlewares (/Users/timothy/Workspace/timothy/test/node_modules/fastify/fastify.js:446:5)
    at middlewareCallback (/Users/timothy/Workspace/timothy/test/node_modules/fastify/fastify.js:434:7)
    at Object.routeHandler [as handler] (/Users/timothy/Workspace/timothy/test/node_modules/fastify/fastify.js:286:7)
    at Router.lookup (/Users/timothy/Workspace/timothy/test/node_modules/find-my-way/index.js:323:17)
    at req.prepare (/Users/timothy/Workspace/timothy/test/node_modules/light-my-request/index.js:72:43)
    at Request.Object.<anonymous>.Request.prepare (/Users/timothy/Workspace/timothy/test/node_modules/light-my-request/lib/request.js:74:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

To Reproduce

Expected behavior

yarn test

Link to repl or repo (highly encouraged)

https://github.com/ygmpkk/readable-stream-error

https://github.com/nodejs/readable-stream/issues/391

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.10.1 - ~/.nvm/versions/node/v8.11.3/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.11.3/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

@mcollina

Bug

Most helpful comment

Hey @ygmpkk, thanks for filing.

Looks like this test should be async (see https://jestjs.io/docs/en/asynchronous)

All 2 comments

Hey @ygmpkk, thanks for filing.

Looks like this test should be async (see https://jestjs.io/docs/en/asynchronous)

awesome

Was this page helpful?
0 / 5 - 0 ratings