Jest: mappedCoverage.addStatement is not a function

Created on 12 May 2017  路  8Comments  路  Source: facebook/jest


Do you want to request a feature or report a bug?

A bug.

What is the current behavior?

I updated my project to Jest 20.0.1 and updated ts-jest to 20.0.3 as well. I tried out the new coverage feature and get following error:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: mappedCoverage.addStatement is not a function

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

You can find a repo here

What is the expected behavior?

Report test coverage.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

"jest": {
    "globals": {
      "__TS_CONFIG__": "./test/tsconfig.json"
    },
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
      "<rootDir>/build"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "setupTestFrameworkScriptFile": "./test/setupTestFramework.ts",
    "mapCoverage": true,
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "moduleNameMapper": {
      "\\.(svg|woff|ttf|eot)$": "<rootDir>/test/__mocks__/fileMock.js",
      "\\.(css)$": "<rootDir>/test/__mocks__/styleMock.js"
    },
    "setupFiles": [
      "./test/setupJest.ts"
    ]
  },

There is also an issue at the ts-jest project: https://github.com/kulshekhar/ts-jest/issues/211 We are not really sure if this is a ts-jest or a Jest issue 馃

Most helpful comment

this solution work me

rm -rf $TMPDIR/react-* && watchman watch-del-all && npm cache clean --force && npm run jest --clearCache

All 8 comments

This only happens when piping the tsc output through babel-jest.

Probably a ts-jest issue.

I meet a "TypeError: mappedCoverage.addStatement is not a function" error while using
without using jest's "istanbul-lib-source-maps" functionality, the whole information is as below:

TypeError: mappedCoverage.addStatement is not a function
at /tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/transformer.js:97:28
at Array.forEach ()
at SourceMapTransformer.processFile (/tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/transformer.js:88:34)
at /tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/transformer.js:169:24
at Array.forEach ()
at SourceMapTransformer.transform (/tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/transformer.js:159:25)
at MapStore.transformCoverage (/tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/map-store.js:143:8)
at /tmp/build/src/node_modules/jest-cli/build/reporters/coverage_reporter.js:115:57
at Generator.next ()
at step (/tmp/build/src/node_modules/jest-cli/build/reporters/coverage_reporter.js:63:191)

PS:
jest version: 22.4.3 and 23.0.1
In my case, there is nothing related with "ts-jest"

Please open up a new issue with reproduction steps

I meet a "TypeError: mappedCoverage.addStatement is not a function" error while using
without using jest's "istanbul-lib-source-maps" functionality, the whole information is as below:

TypeError: mappedCoverage.addStatement is not a function
at /tmp/build/src/node_modules/jest-cli/node_modules/istanbul-lib-source-maps/lib/transformer.js:97:28
at Array.forEach ()

PS:
jest version: 22.4.3
In my case, there is nothing related with "ts-jest"

I'll quote myself from tight above 馃檪

Please open up a new issue with reproduction steps

EDIT: Wait, it's just a copy of the comment above mine again...

this solution work me

rm -rf $TMPDIR/react-* && watchman watch-del-all && npm cache clean --force && npm run jest --clearCache

I am not using ts-jest and I also have this error with expo sdk 36.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bookman25 picture bookman25  路  79Comments

TYRONEMICHAEL picture TYRONEMICHAEL  路  80Comments

pfftdammitchris picture pfftdammitchris  路  76Comments

sterpe picture sterpe  路  70Comments

vitalibozhko picture vitalibozhko  路  138Comments