Istanbul: "else path not taken" for class in ES6

Created on 5 Dec 2016  路  10Comments  路  Source: gotwarlost/istanbul

I hava a problem with the coverage, look:

image

But, written in this way, it works:
image
image

  • Maybe, this way is not correct. Maybe, no best practice.

Most helpful comment

Have same strange issue for React and React Native import statements
image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

All 10 comments

Any update on that?

Actually, I had the same issue and I found this gist https://gist.github.com/pbeshai/7bb7ba4bf257249493de, which I converted to:

// bin/jestPreprocessor.js
var babel = require('babel-core')
var fs = require('fs')

// setup source mapping as per https://github.com/facebook/jest/issues/114
var map_path = function(string) {
  return '/tmp/' + require('crypto').createHash('md5').update(string).digest('hex') + '.map'
}

module.exports = {
  process: function(src, filename) {
    if (!babel.util.canCompile(filename)) {
      return ''
    }

    if (filename.indexOf('node_modules') !== -1) {
      return src
    }

    if (babel.util.canCompile(filename)) {
      // Force inclusion of the polyfill, then append regular compiled output.
      var compiled = babel.transform(src, { filename: filename, sourceMap: true })
      var result = compiled.code

      fs.writeFileSync(map_path(filename), JSON.stringify(compiled.map))

      return result
    }

    return src
  },
}

Then, in my package.json, I have in the Jest section:

"transform": {
      "^.+\\.jsx$": "<rootDir>/node_modules/babel-jest",
      ".*": "<rootDir>/bin/jestPreprocessor"
    }

I hope it will work for you too.

No, doesn't work for me. But thanks anyway :)

What is your configuration ?

Have same strange issue for React and React Native import statements
image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

image

I'm getting the same results. My code has no logic at this point. I tried removing empty lines and the error showed on different lines.

2018-10-23_16-14-14
2018-10-23_16-14-58

+1

Have same strange issue for React and React Native import statements
image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

did you get this to work @olegdeezus ?

Have same strange issue for React and React Native import statements
image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

almost four years now...any solution?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ottes picture ottes  路  36Comments

mbielski picture mbielski  路  37Comments

NiGhTTraX picture NiGhTTraX  路  36Comments

dankohn picture dankohn  路  25Comments

gbahamondezc picture gbahamondezc  路  24Comments