Skip to content
Myr

Document and test things that are _not_ drafted

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent b9cc802 · Browse files · 3 files+53 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+53 added−0 removed

  • tests:+34 added−0 removed
  • other:+19 added−0 removed

3 files+53 added−0 removed

modified:__tests__/base.js+34 added
560 unmodified lines
561 expect(() => m.set("x", 3)).toThrow(562 "Cannot use a proxy that has been revoked"563 )564 })565566 it("does not draft map keys", () => {567 // anything else would be terribly confusing568 const key = {a: 1}569 const map = new Map([[key, 2]])570 const next = produce(map, d => {571 const dKey = Array.from(d.keys())[0]572 expect(isDraft(dKey)).toBe(false)573 expect(dKey).toBe(key)574 dKey.a += 1575 d.set(dKey, d.get(dKey) + 1)576 d.set(key, d.get(key) + 1)577 expect(d.get(key)).toBe(4)578 expect(key.a).toBe(2)579 })580 const entries = Array.from(next.entries())581 expect(entries).toEqual([[key, 4]])582 expect(entries[0][0]).toBe(key)583 expect(entries[0][0].a).toBe(2)584 })585 })586587 describe("set drafts", () => {588 it("supports iteration", () => {
785 unmodified lines
1374 expect(base[0].a).toEqual(1)1375 expect(result[0].a).toEqual(2)1376 })13771378 it("does not draft external data", () => {1379 const externalData = {x: 3}1380 const base = {}1381 const next = produce(base, draft => {1382 // potentially, we *could* draft external data automatically, but only if those statements are not switched...1383 draft.y = externalData1384 draft.y.x += 11385 externalData.x += 11386 })1387 expect(next).toEqual({y: {x: 5}})1388 expect(externalData.x).toBe(5)1389 expect(next.y).toBe(externalData)1390 })13911392 autoFreeze &&1393 test("issue #469, state not frozen", () => {1394 const project = produce(1395 {
532 unmodified lines
modified:docs/complex-objects.md+2 added
modified:docs/pitfalls.md+17 added