Open
Description
openedon Oct 28, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment