Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest.spyOn cannot redefine property #8350

Closed
zachbryant opened this issue Nov 28, 2023 · 2 comments
Closed

jest.spyOn cannot redefine property #8350

zachbryant opened this issue Nov 28, 2023 · 2 comments
Labels

Comments

@zachbryant
Copy link

zachbryant commented Nov 28, 2023

Describe the bug

In my project, upgrading from 1.2.205 leads to this error: TypeError: Cannot redefine property: myFunction at Function.defineProperty (<anonymous>). Seems to be different from other similar errors that I found online such as this one as I am not importing from an index file. The issue goes away when I downgrade to 1.2.205.

Input code

import * as anImport from './myFile'

describe('some test suite', () => {
    it('test 1', () => {
        const spy = jest.spyOn(anImport, 'myFunction').mockReturnValue(0)
        expect(anImport.someOtherFunc()).toBe(false)
    })
})

Config

{
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "tsx": true,
            "decorators": false,
            "dynamicImport": false
        }
    }
}

Playground link (or link to the minimal reproduction)

https://github.com/zachbryant/swc-repro

SWC Info output

Operating System:
Platform: linux
Arch: x64
Machine Type: x86_64
Version: #16~22.04.1-Ubuntu SMP Tue Oct 10 17:11:51 UTC 2023
CPU: (16 cores)
Models: AMD EPYC 7763 64-Core Processor

Binaries:
Node: 18.18.2
npm: 9.8.1
Yarn: 1.22.19
pnpm: 8.10.2

Relevant Packages:
@swc/core: 1.2.213
@swc/helpers: 0.5.1
@swc/types: 0.1.5
typescript: 4.8.4

SWC Config:
output: N/A
.swcrc path: N/A

Next.js info:
output: N/A

Expected behavior

Expected test to pass as is, no issue.

Actual behavior

Test fails with aforementioned error.

Version

1.2.206 and above

Additional context

I tried loose mode etc to no avail. Switching my repo to use mocks/the mock esmodule workaround isn't an option.

I tried 1.2.206 and other higher versions and the error persisted. I'm on the latest of everything.

@kdy1
Copy link
Member

kdy1 commented Nov 28, 2023

#7435

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@kdy1 kdy1 reopened this Nov 28, 2023
@kdy1 kdy1 closed this as completed Nov 28, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Dec 28, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants