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

[Bug]: defineProperty behavior is inconsistent with reality in JSDom #15364

Open
godlanbo opened this issue Oct 28, 2024 · 2 comments
Open

[Bug]: defineProperty behavior is inconsistent with reality in JSDom #15364

godlanbo opened this issue Oct 28, 2024 · 2 comments

Comments

@godlanbo
Copy link

Version

29.7.0

Steps to reproduce

/**
 * @jest-environment jsdom
 */

describe('test', () => {
  it('test', () => {
    const obj = {}
    Object.defineProperty(obj, 'tt', {
      writable: false,
      value: 1,
      configurable: true
    })
    expect(obj.tt).toBe(1)
    Object.defineProperty(obj, 'tt', {
      writable: false,
      value: 2,
      configurable: true
    })
    expect(obj.tt).toBe(2)
  })

  it('jsdom', () => {
    Object.defineProperty(window, 'tt', {
      writable: false,
      value: 1,
      configurable: true
    })
    expect(window.tt).toBe(1)
    Object.defineProperty(window, 'tt', {
      writable: false,
      value: 2,
      configurable: true
    })
    expect(window.tt).toBe(2)
  })
})

Expected behavior

expect consistent behavior of defineProperty on window

Actual behavior

jsdom test case not pass

Additional context

I thought it was a jsdom problem, but I only used jsdom for testing and the result was ok

const jsdom = require('jsdom')
const { JSDOM } = jsdom

const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`)

Object.defineProperty(dom.window, 'JSB', {
  writable: false,
  value: undefined,
  configurable: true
})
console.log(dom.window.JSB) // undefined
Object.defineProperty(dom.window, 'JSB', {
  writable: false,
  value: 1,
  configurable: true
})
console.log(dom.window.JSB) // 1

Environment

System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.20.4 - /usr/local/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 6.14.16 - /opt/homebrew/bin/npm
    pnpm: 7.29.1 - ~/Library/pnpm/pnpm
@godlanbo
Copy link
Author

Well, I looked at the code of jest-enviromment-jsdom and found that it was caused by instantiating the jsdom configuration. This seems to be a problem with jsdom. I have submitted an issue on jsdom.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 27, 2024
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

1 participant