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

Object.freeze breaks toEqual #4298

Closed
6 tasks done
JonathanMEdwards opened this issue Oct 13, 2023 · 0 comments · Fixed by #4303
Closed
6 tasks done

Object.freeze breaks toEqual #4298

JonathanMEdwards opened this issue Oct 13, 2023 · 0 comments · Fixed by #4303
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@JonathanMEdwards
Copy link

Describe the bug

Object.freeze causes toEqual to trap because it is trying to mutate my data. This only happens when it actually finds a difference.

Reproduction

import { expect, test } from 'vitest'
test('vitest trap', () => {
const x = {a: { b: { c: 1 }}}
const y = {a: { b: { c: 2 }}}
Object.freeze(x.a);
expect(x).toEqual(y);
})

Throws the error:
TypeError: Cannot assign to read only property 'b' of object '#'

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.24 GB / 16.00 GB
    Shell: 3.3.1 - /usr/local/bin/fish
  Binaries:
    Node: 20.8.0 - /usr/local/bin/node
    npm: 10.1.0 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 87.1.18.78
    Chrome: 117.0.5938.149
    Safari: 17.0
  npmPackages:
    @vitejs/plugin-react-swc: ^3.4.0 => 3.4.0
    vite: ^4.4.9 => 4.4.9
    vitest: ^0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Oct 13, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants