Skip to content

Fails to run test when importing React components -- 'Cannot find module'  #705

Open
@Michael-Sper

Description

@Michael-Sper

Environment

  1. vscode-jest version: [26.6.3]
  2. node -v: [14.17.0]
  3. npm -v or yarn --version: [npm 6.14.13]
  4. your vscode-jest settings if customized:
   module.exports ={
  
  moduleNameMapper: {
    '\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.js',
    '^meteor/(.*)': '<rootDir>/__mocks__/meteorMocks.js'
  }, 
  transform: {
    '^.+\\.js?$': 'babel-jest'
  },
  transformIgnorePatterns: ['node_modules/(?!@foobar)/'],
  modulePaths:['<rootDir>/ui']

};

- anything else that you think might be relevant? [ ]

babel.config.json:

   {
 "plugins": ["@babel/plugin-proposal-class-properties",
   "@babel/transform-runtime",
   "@babel/plugin-proposal-optional-chaining",
   ["@babel/plugin-proposal-decorators", { "legacy": true }]
 ],
 "presets": [
   "@babel/preset-react",
   "@babel/preset-env"

]
}
  1. Operating system: [Ubuntu 20.04.2 LTS]

Prerequisite

  • are you able to run jest test from the command line? [No]
  • how do you run your tests from the command line? (for example: npm run test or node_modules/.bin/jest) [npm run test]

Steps to Reproduce

Basically all I'm trying to do is import a module, but after many configurations I've tried none seem to work.

import ElementRenderer from '../ui/components/ElementRenderer';
describe('Something', ()=>{
  it('should work', ()=>{
    expect(3).toBe(3);
  });
});

Expected Behavior

Run a simple test

Actual Behavior

Cannot find module '/ui/components/collectionEditor/utils' from 'ui/components/elements/collections/TablePagination.js'

Require stack:
  ui/components/elements/collections/TablePagination.js
  ui/components/elements/ChatWidget.js
  ui/components/ElementRenderer.js
  __tests__/first.test.js

Please note that I'm new to using jest and react, and any light on the issue will be highly appreciated! Thanks!

The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...

Metadata

Metadata

Assignees

No one assigned

    Labels

    external-issueissues caused by external system ( (no fix needed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions