Create-React-App with Jest not working “Cannot find module nodeModuleX from componentY”












0














I'm trying to start testing the components on my project that was created with the Create React App with Jest. I created a simple test file for one component and I'm getting this "error" coming from a component that isn't even related to the component I'm trying to test. I'm using the Create React App, so I can't change jest's config.



That's the test file



/** Home.test.js */

import React from 'react';
import ReactDOM from 'react-dom';
import Home from '../../components/Home';

test('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Home />, div);
});


That's the error



FAIL  src__tests__componentsHome.test.js
● Test suite failed to run

Cannot find module 'signature_pad' from 'Signature.jsx'

at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (src/components/common/inputs/Signature.jsx:3:22)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.031s
Ran all test suites related to changed files.


If I comment the import line of the code on the component Signature.jsx, I get another error from another component:



src__tests__componentsHome.test.js
● Test suite failed to run

TypeError: _WorkerDriverLicenceSchema2.default is not iterable

at Object.<anonymous> (src/components/profiles/worker/forms/WorkerDriverLicences.jsx:35:33)
at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerViewDetails.jsx:18:29)
at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerDetailsModal.jsx:7:26)
at Object.<anonymous> (src/components/common/uiElements/UserDetailsLink.jsx:7:27)
at Object.<anonymous> (src/components/common/uiElements/index.js:13:247)
at Object.<anonymous> (src/components/common/layout/ChangeLog.jsx:5:19)
at Object.<anonymous> (src/components/common/layout/index.js:1:182)
at Object.<anonymous> (src/components/Home.jsx:4:15)
at Object.<anonymous> (src/__tests__/components/Home.test.js:5:13)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.18s
Ran all test suites related to changed files.









share|improve this question





























    0














    I'm trying to start testing the components on my project that was created with the Create React App with Jest. I created a simple test file for one component and I'm getting this "error" coming from a component that isn't even related to the component I'm trying to test. I'm using the Create React App, so I can't change jest's config.



    That's the test file



    /** Home.test.js */

    import React from 'react';
    import ReactDOM from 'react-dom';
    import Home from '../../components/Home';

    test('renders without crashing', () => {
    const div = document.createElement('div');
    ReactDOM.render(<Home />, div);
    });


    That's the error



    FAIL  src__tests__componentsHome.test.js
    ● Test suite failed to run

    Cannot find module 'signature_pad' from 'Signature.jsx'

    at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
    at Object.<anonymous> (src/components/common/inputs/Signature.jsx:3:22)

    Test Suites: 1 failed, 1 total
    Tests: 0 total
    Snapshots: 0 total
    Time: 1.031s
    Ran all test suites related to changed files.


    If I comment the import line of the code on the component Signature.jsx, I get another error from another component:



    src__tests__componentsHome.test.js
    ● Test suite failed to run

    TypeError: _WorkerDriverLicenceSchema2.default is not iterable

    at Object.<anonymous> (src/components/profiles/worker/forms/WorkerDriverLicences.jsx:35:33)
    at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerViewDetails.jsx:18:29)
    at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerDetailsModal.jsx:7:26)
    at Object.<anonymous> (src/components/common/uiElements/UserDetailsLink.jsx:7:27)
    at Object.<anonymous> (src/components/common/uiElements/index.js:13:247)
    at Object.<anonymous> (src/components/common/layout/ChangeLog.jsx:5:19)
    at Object.<anonymous> (src/components/common/layout/index.js:1:182)
    at Object.<anonymous> (src/components/Home.jsx:4:15)
    at Object.<anonymous> (src/__tests__/components/Home.test.js:5:13)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

    Test Suites: 1 failed, 1 total
    Tests: 0 total
    Snapshots: 0 total
    Time: 1.18s
    Ran all test suites related to changed files.









    share|improve this question



























      0












      0








      0







      I'm trying to start testing the components on my project that was created with the Create React App with Jest. I created a simple test file for one component and I'm getting this "error" coming from a component that isn't even related to the component I'm trying to test. I'm using the Create React App, so I can't change jest's config.



      That's the test file



      /** Home.test.js */

      import React from 'react';
      import ReactDOM from 'react-dom';
      import Home from '../../components/Home';

      test('renders without crashing', () => {
      const div = document.createElement('div');
      ReactDOM.render(<Home />, div);
      });


      That's the error



      FAIL  src__tests__componentsHome.test.js
      ● Test suite failed to run

      Cannot find module 'signature_pad' from 'Signature.jsx'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (src/components/common/inputs/Signature.jsx:3:22)

      Test Suites: 1 failed, 1 total
      Tests: 0 total
      Snapshots: 0 total
      Time: 1.031s
      Ran all test suites related to changed files.


      If I comment the import line of the code on the component Signature.jsx, I get another error from another component:



      src__tests__componentsHome.test.js
      ● Test suite failed to run

      TypeError: _WorkerDriverLicenceSchema2.default is not iterable

      at Object.<anonymous> (src/components/profiles/worker/forms/WorkerDriverLicences.jsx:35:33)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerViewDetails.jsx:18:29)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerDetailsModal.jsx:7:26)
      at Object.<anonymous> (src/components/common/uiElements/UserDetailsLink.jsx:7:27)
      at Object.<anonymous> (src/components/common/uiElements/index.js:13:247)
      at Object.<anonymous> (src/components/common/layout/ChangeLog.jsx:5:19)
      at Object.<anonymous> (src/components/common/layout/index.js:1:182)
      at Object.<anonymous> (src/components/Home.jsx:4:15)
      at Object.<anonymous> (src/__tests__/components/Home.test.js:5:13)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:189:7)

      Test Suites: 1 failed, 1 total
      Tests: 0 total
      Snapshots: 0 total
      Time: 1.18s
      Ran all test suites related to changed files.









      share|improve this question















      I'm trying to start testing the components on my project that was created with the Create React App with Jest. I created a simple test file for one component and I'm getting this "error" coming from a component that isn't even related to the component I'm trying to test. I'm using the Create React App, so I can't change jest's config.



      That's the test file



      /** Home.test.js */

      import React from 'react';
      import ReactDOM from 'react-dom';
      import Home from '../../components/Home';

      test('renders without crashing', () => {
      const div = document.createElement('div');
      ReactDOM.render(<Home />, div);
      });


      That's the error



      FAIL  src__tests__componentsHome.test.js
      ● Test suite failed to run

      Cannot find module 'signature_pad' from 'Signature.jsx'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (src/components/common/inputs/Signature.jsx:3:22)

      Test Suites: 1 failed, 1 total
      Tests: 0 total
      Snapshots: 0 total
      Time: 1.031s
      Ran all test suites related to changed files.


      If I comment the import line of the code on the component Signature.jsx, I get another error from another component:



      src__tests__componentsHome.test.js
      ● Test suite failed to run

      TypeError: _WorkerDriverLicenceSchema2.default is not iterable

      at Object.<anonymous> (src/components/profiles/worker/forms/WorkerDriverLicences.jsx:35:33)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerViewDetails.jsx:18:29)
      at Object.<anonymous> (src/components/profiles/worker/subComponents/WorkerDetailsModal.jsx:7:26)
      at Object.<anonymous> (src/components/common/uiElements/UserDetailsLink.jsx:7:27)
      at Object.<anonymous> (src/components/common/uiElements/index.js:13:247)
      at Object.<anonymous> (src/components/common/layout/ChangeLog.jsx:5:19)
      at Object.<anonymous> (src/components/common/layout/index.js:1:182)
      at Object.<anonymous> (src/components/Home.jsx:4:15)
      at Object.<anonymous> (src/__tests__/components/Home.test.js:5:13)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:189:7)

      Test Suites: 1 failed, 1 total
      Tests: 0 total
      Snapshots: 0 total
      Time: 1.18s
      Ran all test suites related to changed files.






      reactjs jestjs enzyme






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 6:23









      skyboyer

      3,29611128




      3,29611128










      asked Nov 20 at 5:57









      Rafael Grilli

      429314




      429314





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387052%2fcreate-react-app-with-jest-not-working-cannot-find-module-nodemodulex-from-comp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387052%2fcreate-react-app-with-jest-not-working-cannot-find-module-nodemodulex-from-comp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]