manual.js
This file
Path
__tests__/manual.js
145 lines · 3.1 KiB · JavaScript
Last changed by
chore: fix Buffer deprecation warning in test (#706)Grzegorz Rozdzialikbefore adoptiond75de70
History of this fileTake it
The walk stopped after 200 commits: lines older than fbae585 point at it.
docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 1–6why, one step back1"use strict"2import {3 setUseProxies,4 createDraft,5 finishDraft,6 produce,Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 7–9why, one step back7 isDraft,8 enableAllPlugins9} from "../src/immer"docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 10why, one step back10Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 11–12why, one step back11enableAllPlugins()12chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec
lines 13–14why, one step back13const isProd = process.env.NODE_ENV === "production"14docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 15–25why, one step back15runTests("proxy", true)16runTests("es5", false)1718function runTests(name, useProxies) {19 describe("manual - " + name, () => {20 beforeAll(() => {21 setUseProxies(useProxies)22 })2324 it("should check arguments", () => {25 expect(() => createDraft(3)).toThrowErrorMatchingSnapshot()chore: fix Buffer deprecation warning in test (#706)Grzegorz Rozdzialikbefore adoptiond75de70
line 26why, one step back26 const buf = Buffer.from([])docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 27–45why, one step back27 expect(() => createDraft(buf)).toThrowErrorMatchingSnapshot()28 expect(() => finishDraft({})).toThrowErrorMatchingSnapshot()29 })3031 it("should support manual drafts", () => {32 const state = [{}, {}, {}]3334 const draft = createDraft(state)35 draft.forEach((item, index) => {36 item.index = index37 })3839 const result = finishDraft(draft)4041 expect(result).not.toBe(state)42 expect(result).toEqual([{index: 0}, {index: 1}, {index: 2}])43 expect(state).toEqual([{}, {}, {}])44 })45chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec
lines 46–48why, one step back46 if (!isProd)47 it("cannot modify after finish", () => {48 const state = {a: 1}docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
line 49why, one step back49chore: Merge branch 'master' of github.com:immerjs/immerMichel Weststratebefore adoption6c62eec
lines 50–56why, one step back50 const draft = createDraft(state)51 draft.a = 252 expect(finishDraft(draft)).toEqual({a: 2})53 expect(() => {54 draft.a = 355 }).toThrowErrorMatchingSnapshot()56 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 57–106why, one step back5758 it("should support patches drafts", () => {59 const state = {a: 1}6061 const draft = createDraft(state)62 draft.a = 263 draft.b = 36465 const listener = jest.fn()66 const result = finishDraft(draft, listener)6768 expect(result).not.toBe(state)69 expect(result).toEqual({a: 2, b: 3})70 expect(listener.mock.calls).toMatchSnapshot()71 })7273 it("should handle multiple create draft calls", () => {74 const state = {a: 1}7576 const draft = createDraft(state)77 draft.a = 27879 const draft2 = createDraft(state)80 draft2.b = 38182 const result = finishDraft(draft)8384 expect(result).not.toBe(state)85 expect(result).toEqual({a: 2})8687 draft2.a = 488 const result2 = finishDraft(draft2)89 expect(result2).not.toBe(result)90 expect(result2).toEqual({a: 4, b: 3})91 })9293 it("combines with produce - 1", () => {94 const state = {a: 1}9596 const draft = createDraft(state)97 draft.a = 298 const res1 = produce(draft, d => {99 d.b = 3100 })101 draft.b = 4102 const res2 = finishDraft(draft)103 expect(res1).toEqual({a: 2, b: 3})104 expect(res2).toEqual({a: 2, b: 4})105 })106Immer 7Michel Weststratebefore adoption467ea5d
line 107why, one step back107 it("combines with produce - 2", () => {docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 108–130why, one step back108 const state = {a: 1}109110 const res1 = produce(state, draft => {111 draft.b = 3112 const draft2 = createDraft(draft)113 draft.c = 4114 draft2.d = 5115 const res2 = finishDraft(draft2)116 expect(res2).toEqual({117 a: 1,118 b: 3,119 d: 5120 })121 draft.d = 2122 })123 expect(res1).toEqual({124 a: 1,125 b: 3,126 c: 4,127 d: 2128 })129 })130Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 131–135why, one step back131 !global.USES_BUILD &&132 it("should not finish drafts from produce", () => {133 produce({x: 1}, draft => {134 expect(() => finishDraft(draft)).toThrowErrorMatchingSnapshot()135 })docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585
lines 136–145why, one step back136 })137138 it("should not finish twice", () => {139 const draft = createDraft({a: 1})140 draft.a++141 finishDraft(draft)142 expect(() => finishDraft(draft)).toThrowErrorMatchingSnapshot()143 })144 })145}