GitShow/ljharb/mock-property
ljharb

mock-property

Given an object and a property, replaces a property descriptor (or deletes it), and returns a thunk to restore it.

by ljharb
definedeletedescriptormockobjectpropertytesttesting
Star on GitHubForknpm

JavaScript

6 stars1 forks1 contributorQuiet · 2mo agoSince 2022MIT

Meet the team

See all 1 on GitHub →
ljharb
ljharb51 contributions

Languages

View on GitHub →
JavaScript100%

Commit activity

Last 12 weeks · 12 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
85
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent fixes

View closed PRs →
shadowspawn
Simple save/restore patternClosedIssue

For simple use by people unfamiliar with descriptors, but wanting to safely put back the old state after overwriting a property, a simple save and restore might be useful. Two cases where I have wanted to do this are setting an environment variable for a unit test, and hacking to run a unit test. I suspect this is equivalent to is a delete in the first operation to clear the way for whatever I do, and perhaps doesn't make sense as a "mock" pattern. Could be wishful thinking that this might be a possible helper routine. 😄 Edit: a better description of the usage pattern might be "stash" and "restore". e.g.

shadowspawn · 4y ago
Structured data for AI agents

Repository: ljharb/mock-property. Description: Given an object and a property, replaces a property descriptor (or deletes it), and returns a thunk to restore it. Stars: 6, Forks: 1. Primary language: JavaScript. Languages: JavaScript (100%). License: MIT. Topics: define, delete, descriptor, mock, object, property, test, testing, value. Open PRs: 0, open issues: 1. Last activity: 2mo ago. Community health: 85%. Top contributors: ljharb.

·@ofershap

Replace github.com with gitshow.dev