TypeError: mappedCoverage.addStatement is not a function
See original GitHub issue- Issue
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
- Expected behavior
Coverage should run.
- my config
"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"
]
},
Issue Analytics
- State:
- Created 6 years ago
- Comments:37 (19 by maintainers)
Top Results From Across the Web
TypeError: mappedCoverage.addStatement is not a function ...
Bug Report I have one repo after the upgrade to v24.1 im getting this error TypeError: mappedCoverage.addStatement is not a function as a ......
Read more >TypeError: mappedCoverage.addStatement is not a function
Issue. 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...
Read more >mocha nyc and source maps - typescript - Stack Overflow
build/tests/**/*.js" mappedCoverage.addStatement is not a function. However if I set all to false in the .nycrc.json file, then it doesn't ...
Read more >Code Transformation - Jest
A transformer is a module that provides a method for transforming source files. For example, if you wanted to be able to use...
Read more >Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve had another look into this - the issue (at least with my config) is when
allowSyntheticDefaultImports
is set totrue
. If set, the preprocessor runs files throughbabel-jest
and appends a.js
extension onto them. When the coverage is generated, both the.ts
/.tsx
and.ts.js
/.tsx.js
files are run through the coverage generator, but source maps are only found for.ts.js
/.tsx.js
files, so the original files encounter the problems I described above with missing source maps.I’m afraid this is about as far as I can take it in terms of a fix, but I hope the above info is helpful to whoever picks this up.
I had this issue at work last week, but being relatively new to TypeScript I assumed it was some form of configuration I’d set incorrectly. I didn’t find the problem, but I traced it down to
istanbul-lib-source-maps
- it appears that it’s unable to find a source map, so it just uses a file coverage object for the given file:https://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-lib-source-maps/lib/transformer.js#L161
Then due to this it doesn’t instantiate
MappedCoverage
:https://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-lib-source-maps/lib/transformer.js#L152
This is when I assumed I’d screwed up generating source maps and went back to experimenting with that, but didn’t get any further before I left for the weekend. Only thing I really tried doing was using
inlineSourceMap
instead ofsourceMap
.The only other bits of info I can give at the moment that may help is that I’m also pretty sure if I put in a check for
addStatement
being available before it is called (along withaddFunction
andaddBranch
which also are missing), it did go ahead and generate everything successfully as far as I could see. I also had it working on a branch that just contained a couple of tests for very basic functions in.ts
files, but when.tsx
files and Enzyme were threw into the mix as well that’s when the issues started.