Skip to content

[Bug]: rs.mock() loads real implementation (executing side effects) #745

@jhage-snapsheet

Description

@jhage-snapsheet

Version

System:
    OS: macOS 15.6
    CPU: (14) arm64 Apple M4 Pro
    Memory: 92.91 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 142.0.7444.177
    Firefox: 141.0
    Safari: 18.6
  npmPackages:
    @rstest/core: latest => 0.7.1

Details

As far as I can tell, the rstest implementation of mocking is actually loading the "source" file before applying the mock. I don't see that this is happening with jest

In our case we have endless side effects in our "source" files and can't justify refactoring right now

Reproduce link

https://github.com/jhage-snapsheet/rstest-side-effect-mock

Reproduce Steps

  1. npm run test or DEBUG=rstest npm run test
  2. observe "touches" variables are incremented instead of undefined
  3. npm run test:jest
  4. observe "touches" variables are not incremented

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions