Skip to content

Commit

Permalink
fix: use Object.defineProperties over Object.assign for mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Jul 10, 2024
1 parent 119b0ad commit aaedc9f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jest.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function override(resolved, lax = false) {

// We want to skip overriding frozen properties that already match, e.g. fs.constants
const filtered = Object.entries(value).filter(([k, v]) => !(k in {}) && current[k] !== v)
Object.assign(current, Object.fromEntries(filtered))
const access = { configurable: true, enumerable: true, writable: true }
const definitions = Object.fromEntries(filtered.map(([k, value]) => [k, { value, ...access }]))
Object.defineProperties(current, definitions)
if (!lax) assert.deepEqual({ ...current }, value)
}

Expand Down

0 comments on commit aaedc9f

Please sign in to comment.