vendredi 15 juin 2018

Imports while testing with Jest fail

so I have React component that works well in the browser, but fails to render while testing. I am using Jest, and the component in question is a wrapper around React Sortable. While trying to launch the test, I get "_sortablejs2.default.create is not a function" error, which I have found out that is caused by imports (i.e. require('react')) returning 'undefined'. Why might that be? Other tests that I have work just fine.

Test itself:

let renderer = TestRenderer.create(
      <DragAndDropSelector
        selected={[]}
        choices={[]}
        selectedChange={ (a, b, c) => {return a} }
      />
  );
  expect(renderer.toJSON()).toMatchSnapshot();
});

My package json:

{
"name": "<Redacted/>",
"version": "0.1.0",
"private": true,
"dependencies": {
    "axios": "0.17.1",
    "babel-eslint": "8.2.3",
    "faker": "4.1.0",
    "file-saver": "1.3.8",
    "history": "4.7.2",
    "html-to-react": "1.3.3",
    "immutability-helper": "2.6.6",
    "lodash": "4.17.5",
    "moment": "2.21.0",
    "npm": "6.1.0",
    "npm-run-all": "4.1.2",
    "react": "16.2.0",
    "react-cookie": "2.1.4",
    "react-datepicker": "1.4.1",
    "react-dates": "16.6.1",
    "react-dom": "16.2.0",
    "react-redux": "5.0.7",
    "react-redux-toastr": "^7.3.0",
    "react-router": "4.2.0",
    "react-router-dom": "4.2.2",
    "react-scripts": "1.1.0",
    "react-sortablejs": "^1.3.6",
    "react-test-renderer": "16.2.0",
    "redux": "3.7.2",
    "redux-dehydrate": "0.0.2",
    "redux-logger": "3.0.6",
    "redux-persist": "5.6.5",
    "redux-thunk": "2.2.0",
    "semantic-ui": "2.3.1",
    "semantic-ui-react": "0.78.2",
    "sortablejs": "^1.7.0"
},
"scripts": {
    "build-css": "less-watch-compiler --run-once src src",
    "watch-css": "npm run build-css && less-watch-compiler src src",
    "start-js": "PORT=3000 react-scripts start --host 0.0.0.0",
    "start": "npm-run-all -p watch-css start-js",
    "build-js": "react-scripts build",
    "build": "npm-run-all build-css build-js",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
},
"devDependencies": {
    "less-watch-compiler": "1.11.0",
    "redux-mock-store": "1.5.1",
    "serve": "6.5.3"
},
"homepage__doc": "See VERSION in config/config.js, version should be the same",
"homepage": "/2.1/"

}

Im stumped, so any help would be appreciated:)

Aucun commentaire:

Enregistrer un commentaire