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

TypeError: Cannot redefine property after upgrading to v1.5.0 #5625

Closed
6 tasks done
testrobpoc opened this issue Apr 26, 2024 · 2 comments
Closed
6 tasks done

TypeError: Cannot redefine property after upgrading to v1.5.0 #5625

testrobpoc opened this issue Apr 26, 2024 · 2 comments

Comments

@testrobpoc
Copy link

Describe the bug

Hello, I'm facing an issue when I tried to upgrade vitest version from 1.4.0 to 1.5.0. No code was changed, and now on v1.5.0 I'm getting TypeError: Cannot redefine property: error on some of my unit tests.

Screenshot 2024-04-26 at 11 57 11

It works fine on v1.4.0
It dosn't work on v1.5.0, v1.5.1, v1.5.2

Reproduction

https://stackblitz.com/edit/vitejs-vite-pq9gts?file=package.json,src%2Fapp%2FAuthGuard.tsx,src%2Fapp%2FAuthGuard.test.tsx

NOTE: if you downgrade vitest to v.1.4.0 it should work fine.

System Info

"@vitest/ui": "1.5.0",
"vitest": "1.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"

Node version: v20.11.1

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

This happens because react-oidc-context is now imported as an ES module which doesn't support spying. You need to add it to server.deps.inline for Vitest to patch the module:

export default defineConfig({
  test: {
    server: {
      deps: {
        inline: ['react-oidc-context']
      }
    }
  }
})

@testrobpoc
Copy link
Author

Amazing, thank you @sheremet-va all good now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants