test: improve "property descriptor" tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by aleclarson · committed by Alec Larson · parent 14d7e3c · Browse files · 1 file·+25 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+25 added−17 removed
- tests:+25 added−17 removed
Provenance
- Commit
a84eea5- Tree
0092b5d- Author
aleclarson <alec.stanford.larson@gmail.com>- Committer
Alec Larson <alec.stanford.larson@gmail.com>- Parent
14d7e3c
1 file changed+25 added−17 removed
modified:__tests__/base.js+25 added-17 removed
111 unmodified lines112 113 it("can get property descriptors", () => {114 const getDescriptor = Object.getOwnPropertyDescriptor115 const baseState = deepFreeze([{a: 1}])116- produce(baseState, draft => {117- const obj = draft[0]116+ produce(baseState, arr => {117+ const obj = arr[0]118+ const desc = {119+ configurable: true,120+ enumerable: true,121+ ...(useProxies && {writable: true})122+ }123 124 // Known property120- expect(getDescriptor(obj, "a")).toMatchObject({121- configurable: true,122- enumerable: true123- })124- expect(getDescriptor(draft, 0)).toMatchObject({125- configurable: true,126- enumerable: true127- })125+ expect(getDescriptor(obj, "a")).toMatchObject(desc)126+ expect(getDescriptor(arr, 0)).toMatchObject(desc)127 128 // Deleted property129 delete obj.a131- draft.pop()130+ arr.pop()131 expect(getDescriptor(obj, "a")).toBeUndefined()133- expect(getDescriptor(draft, 0)).toBeUndefined()132+ expect(getDescriptor(arr, 0)).toBeUndefined()133 134 // Unknown property135 expect(getDescriptor(obj, "b")).toBeUndefined()137- expect(getDescriptor(draft, 100)).toBeUndefined()136+ expect(getDescriptor(arr, 100)).toBeUndefined()137 138 // Added property139 obj.b = 2141- draft[100] = 1140+ arr[100] = 1141 expect(getDescriptor(obj, "b")).toBeDefined()143- expect(getDescriptor(draft, 100)).toBeDefined()142+ expect(getDescriptor(arr, 100)).toBeDefined()143 })144 })145 146 describe("array drafts", () => {154 unmodified lines301 })302 303 it("preserves non-enumerable properties", () => {304 const baseState = {}305+ // Non-enumerable object property306 Object.defineProperty(baseState, "foo", {307- value: true,307+ value: {a: 1},308 enumerable: false309 })310+ // Non-enumerable primitive property311+ Object.defineProperty(baseState, "bar", {312+ value: 1,313+ enumerable: false314+ })315 const nextState = produce(baseState, s => {316 expect(s.foo).toBeTruthy()317 expect(isEnumerable(s, "foo")).toBeFalsy()313- s.bar = true318+ s.bar++319+ expect(isEnumerable(s, "foo")).toBeFalsy()320+ s.foo.a++321+ expect(isEnumerable(s, "foo")).toBeFalsy()322 })323 expect(nextState.foo).toBeTruthy()324 expect(isEnumerable(nextState, "foo")).toBeFalsy()325 })845 unmodified lines