Victory: How to test Victory Chart using Jest?

Created on 26 May 2017  路  3Comments  路  Source: FormidableLabs/victory

When I try using Jest for unit test, I got this error:

/node_modules/victory-native/lib/index.js:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import {
^^^^^^
SyntaxError: Unexpected token import

Is there any suggestion for this?

All 3 comments

import is not supported by ES5, so it sounds like you don't have Jest configured to convert your ES6 to ES5 (or TypeScript to ES5 if you're using that).

See here for configuring Jest to work with Babel: https://facebook.github.io/jest/docs/getting-started.html#using-babel

you can fix it by using transformIgnorePatterns config

example

  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!victory-native)/"
    ]
  },

I still think it's an issue that victory-native is published with the ES6 and not published with the ES5 compiled version tho

Was this page helpful?
0 / 5 - 0 ratings