Eliav2 / react-xarrows

Draw arrows (or lines) between components in React!
https://codesandbox.io/embed/github/Eliav2/react-xarrows/tree/master/examples?fontsize=14&hidenavigation=1&theme=dark
MIT License
584 stars 75 forks source link

Problems testing my app #27

Closed betCG closed 4 years ago

betCG commented 4 years ago

Hi! i'm having this error while testing my project, it's caused by the library. I'm kinda a noob with testing so if anyone can help me to fix this that would be great.

` FAIL src/components/navbar/NavBar.test.js ● Test suite failed to run

/Users/bchavez/Documents/km-careerpath/ui/node_modules/react-xarrows/lib/index.js:12
import React, { useRef, useEffect, useState } from "react";
^^^^^^

SyntaxError: Cannot use import statement outside a module

  1 | import React, { useState } from "react";
> 2 | import Xarrow from "react-xarrows";
    | ^
  3 | import "./TreeNode.scss";
  4 |
  5 | function TreeNode(props) {

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at Object.<anonymous> (src/components/tree-node/TreeNode.js:2:1)`
irfanfs commented 4 years ago

i am also facing this issue :(

Eliav2 commented 4 years ago

Actually I don't know why it happens.. How I can reproduce this issue? Have any suggestions why it can happen?

vparandii commented 4 years ago

@betCG @irfans Just solved this issue: if you use create-react-app and react-app-rewired:

// config-overrides.js
module.exports = {
  jest: (config) => {
    config.transformIgnorePatterns = ['/node_modules/(?!react-xarrows).+\\.js$'];
    return config;
  },
};

if you use jest directly:

// package.json
"jest" : {
  "transformIgnorePatterns": [
    "/node_modules/(?!react-xarrows).+\\.js$"
  ]
}

BUT now I'm facing a new issue:

TypeError: Cannot destructure property `startPointObj` of 'undefined' or 'null'.

🤭

Eliav2 commented 4 years ago

something is unvalid or missing with the typescript/babel/webpack configuration files. @walandemar your answer is just a workaround because the files should've already been transformed (means plain javascript files and not typescript files), what you actually do is just transforming ts files to js before testing.

For some reason, it seems that jest is referring to src/index.tsx instead the complied version lib/index.js, I've no idea why.

if someone here has some deep knowledge in these settings, please clone the repo, fix, and open a pull request with the fix. I don't know what causes this and I to fix it.

Eliav2 commented 4 years ago

It was just an issue related to tsconifg file. the target javascript version the ts compiler used was esnext, now, in v1.5.0 the ts files are compiled to javascript version commonjs and now jest should work properly. please update to 1.5.0 and check if the issue still exists.