Skip to content

[Feature Request] jest.mock path detection and improvement #946

Open
@kimyu92

Description

@kimyu92

Environment

  1. vscode-jest version: v4.6.0
  2. node -v: node 16+
  3. npm -v or yarn --version: 1.x
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected):
  5. your vscode-jest settings if customized: no
    • jest.jestCommandLine?
    • jest.autoRun?
    • anything else that you think might be relevant?
  6. Operating system: Mac OS 13.0.x

Prerequisite

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

Steps to Reproduce

jest.mock('./foo/bar.js', () => ({
  foo: false,
  bar: true,
}));

Relevant Debug Info

In order to improve the quality of developer of using jest in vscode, when trying to mock a module from relative path, it doesn't work like regular imported path, where there is no

  1. auto-suggestion for possible import
  2. file path being highlighted as hyperlink to provide convenient lookup
  3. refactoring on update import on file move simply will break the path

Expected Behavior

  1. The detection of reference path that allows hyperlink to actual file similar to how import works
  2. Allow updateImportsOnFileMove when moving files

Actual Behavior

  1. It's a regular string where the file might not exist
  2. Refactoring causing spec failures

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions