istanbul icon indicating copy to clipboard operation
istanbul copied to clipboard

"else path not taken" for class in ES6

Open brunoosilva opened this issue 8 years ago • 10 comments

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.

brunoosilva avatar Dec 05 '16 10:12 brunoosilva

Any update on that?

albertolive avatar Dec 20 '16 16:12 albertolive

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.

loick avatar Jan 02 '17 10:01 loick

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

albertolive avatar Jan 03 '17 08:01 albertolive

What is your configuration ?

loick avatar Jan 09 '17 23:01 loick

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"]
}

olegdeezus avatar Mar 28 '17 20:03 olegdeezus

image

Ratikant01 avatar Jul 27 '18 09:07 Ratikant01

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

lend-a-tailor avatar Oct 23 '18 20:10 lend-a-tailor

+1

amallo avatar May 09 '19 18:05 amallo

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 ?

sammysium avatar Sep 12 '20 16:09 sammysium

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?

sammysium avatar Oct 14 '20 15:10 sammysium