test: use Jest snapshots for expected errors
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alec Larson · committed by Alec Larson · parent a951f40 · Browse files · 7 files·+212 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+212 added−37 removed
- tests:+212 added−37 removed
Provenance
- Commit
0ad9a91- Tree
7e0e681- Author
Alec Larson <alec.stanford.larson@gmail.com>- Committer
Alec Larson <alec.stanford.larson@gmail.com>- Parent
a951f40
7 files changed+212 added−37 removed
added:__tests__/__snapshots__/base.js.snap+157 added
1+// Jest Snapshot v1, https://goo.gl/fbAQLP2+3+exports[`base functionality - es5 (autofreeze) async recipe function works with rejected promises 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":0,\\"b\\":1}"`;4+5+exports[`base functionality - es5 (autofreeze) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;6+7+exports[`base functionality - es5 (autofreeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;8+9+exports[`base functionality - es5 (autofreeze) revokes the draft once produce returns 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;10+11+exports[`base functionality - es5 (autofreeze) revokes the draft once produce returns 2`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;12+13+exports[`base functionality - es5 (autofreeze) revokes the draft once produce returns 3`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;14+15+exports[`base functionality - es5 (autofreeze) revokes the draft once produce returns 4`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;16+17+exports[`base functionality - es5 (autofreeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;18+19+exports[`base functionality - es5 (autofreeze) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;20+21+exports[`base functionality - es5 (autofreeze)(patch listener) async recipe function works with rejected promises 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":0,\\"b\\":1}"`;22+23+exports[`base functionality - es5 (autofreeze)(patch listener) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;24+25+exports[`base functionality - es5 (autofreeze)(patch listener) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;26+27+exports[`base functionality - es5 (autofreeze)(patch listener) revokes the draft once produce returns 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;28+29+exports[`base functionality - es5 (autofreeze)(patch listener) revokes the draft once produce returns 2`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;30+31+exports[`base functionality - es5 (autofreeze)(patch listener) revokes the draft once produce returns 3`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;32+33+exports[`base functionality - es5 (autofreeze)(patch listener) revokes the draft once produce returns 4`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;34+35+exports[`base functionality - es5 (autofreeze)(patch listener) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;36+37+exports[`base functionality - es5 (autofreeze)(patch listener) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;38+39+exports[`base functionality - es5 (no freeze) async recipe function works with rejected promises 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":0,\\"b\\":1}"`;40+41+exports[`base functionality - es5 (no freeze) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;42+43+exports[`base functionality - es5 (no freeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;44+45+exports[`base functionality - es5 (no freeze) revokes the draft once produce returns 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;46+47+exports[`base functionality - es5 (no freeze) revokes the draft once produce returns 2`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;48+49+exports[`base functionality - es5 (no freeze) revokes the draft once produce returns 3`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;50+51+exports[`base functionality - es5 (no freeze) revokes the draft once produce returns 4`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;52+53+exports[`base functionality - es5 (no freeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;54+55+exports[`base functionality - es5 (no freeze) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;56+57+exports[`base functionality - proxy (autofreeze) array drafts throws when a non-numeric property is added 1`] = `"Immer only supports setting array indices and the 'length' property"`;58+59+exports[`base functionality - proxy (autofreeze) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;60+61+exports[`base functionality - proxy (autofreeze) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;62+63+exports[`base functionality - proxy (autofreeze) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;64+65+exports[`base functionality - proxy (autofreeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;66+67+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;68+69+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;70+71+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;72+73+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;74+75+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;76+77+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;78+79+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;80+81+exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;82+83+exports[`base functionality - proxy (autofreeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;84+85+exports[`base functionality - proxy (autofreeze) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;86+87+exports[`base functionality - proxy (autofreeze) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Object.setPrototypeOf() cannot be used on an Immer draft"`;88+89+exports[`base functionality - proxy (autofreeze) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;90+91+exports[`base functionality - proxy (autofreeze)(patch listener) array drafts throws when a non-numeric property is added 1`] = `"Immer only supports setting array indices and the 'length' property"`;92+93+exports[`base functionality - proxy (autofreeze)(patch listener) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;94+95+exports[`base functionality - proxy (autofreeze)(patch listener) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;96+97+exports[`base functionality - proxy (autofreeze)(patch listener) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;98+99+exports[`base functionality - proxy (autofreeze)(patch listener) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;100+101+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;102+103+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;104+105+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;106+107+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;108+109+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;110+111+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;112+113+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;114+115+exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;116+117+exports[`base functionality - proxy (autofreeze)(patch listener) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;118+119+exports[`base functionality - proxy (autofreeze)(patch listener) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;120+121+exports[`base functionality - proxy (autofreeze)(patch listener) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Object.setPrototypeOf() cannot be used on an Immer draft"`;122+123+exports[`base functionality - proxy (autofreeze)(patch listener) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;124+125+exports[`base functionality - proxy (no freeze) array drafts throws when a non-numeric property is added 1`] = `"Immer only supports setting array indices and the 'length' property"`;126+127+exports[`base functionality - proxy (no freeze) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;128+129+exports[`base functionality - proxy (no freeze) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;130+131+exports[`base functionality - proxy (no freeze) recipe functions cannot return a modified child draft 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;132+133+exports[`base functionality - proxy (no freeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;134+135+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;136+137+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;138+139+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;140+141+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;142+143+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;144+145+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;146+147+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;148+149+exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;150+151+exports[`base functionality - proxy (no freeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;152+153+exports[`base functionality - proxy (no freeze) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;154+155+exports[`base functionality - proxy (no freeze) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Object.setPrototypeOf() cannot be used on an Immer draft"`;156+157+exports[`base functionality - proxy (no freeze) throws when the draft is modified and another object is returned 1`] = `"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;added:__tests__/__snapshots__/curry.js.snap+17 added
1+// Jest Snapshot v1, https://goo.gl/fbAQLP2+3+exports[`curry - es5 should check arguments 1`] = `"The first or second argument to \`produce\` must be a function"`;4+5+exports[`curry - es5 should check arguments 2`] = `"The first or second argument to \`produce\` must be a function"`;6+7+exports[`curry - es5 should check arguments 3`] = `"The first or second argument to \`produce\` must be a function"`;8+9+exports[`curry - es5 should check arguments 4`] = `"The third argument to \`produce\` must be a function or undefined"`;10+11+exports[`curry - proxy should check arguments 1`] = `"The first or second argument to \`produce\` must be a function"`;12+13+exports[`curry - proxy should check arguments 2`] = `"The first or second argument to \`produce\` must be a function"`;14+15+exports[`curry - proxy should check arguments 3`] = `"The first or second argument to \`produce\` must be a function"`;16+17+exports[`curry - proxy should check arguments 4`] = `"The third argument to \`produce\` must be a function or undefined"`;modified:__tests__/__snapshots__/manual.js.snap+10 added-10 removed
1 // Jest Snapshot v1, https://goo.gl/fbAQLP2 3 exports[`manual - es5 cannot modify after finish 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":2}"`;4 5-exports[`manual - es5 should check arguments 1`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;5+exports[`manual - es5 should check arguments 1`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;6 7-exports[`manual - es5 should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;7+exports[`manual - es5 should check arguments 2`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;8 9-exports[`manual - es5 should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;9+exports[`manual - es5 should check arguments 3`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;10 11-exports[`manual - es5 should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;11+exports[`manual - es5 should not finish drafts from produce 1`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;12 13-exports[`manual - es5 should not finish twice 1`] = `"The draft provided was has already been finished"`;13+exports[`manual - es5 should not finish twice 1`] = `"The given draft is already finalized"`;14 15 exports[`manual - es5 should support patches drafts 1`] = `16 Array [17 Array [33 unmodified lines51 `;52 53 exports[`manual - proxy cannot modify after finish 1`] = `"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":2}"`;54 55-exports[`manual - proxy should check arguments 1`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;55+exports[`manual - proxy should check arguments 1`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;56 57-exports[`manual - proxy should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;57+exports[`manual - proxy should check arguments 2`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;58 59-exports[`manual - proxy should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;59+exports[`manual - proxy should check arguments 3`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;60 61-exports[`manual - proxy should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;61+exports[`manual - proxy should not finish drafts from produce 1`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;62 63-exports[`manual - proxy should not finish twice 1`] = `"The draft provided was has already been finished"`;63+exports[`manual - proxy should not finish twice 1`] = `"The given draft is already finalized"`;64 65 exports[`manual - proxy should support patches drafts 1`] = `66 Array [67 Array [34 unmodified linesadded:__tests__/__snapshots__/patch.js.snap+7 added
1+// Jest Snapshot v1, https://goo.gl/fbAQLP2+3+exports[`applyPatches throws when \`op\` is not "add", "replace", nor "remove" 1`] = `"Unsupported patch operation: copy"`;4+5+exports[`applyPatches throws when \`path\` cannot be resolved 1`] = `"Cannot apply patch, path doesn't resolve: a/b"`;6+7+exports[`applyPatches throws when \`path\` cannot be resolved 2`] = `"Cannot apply patch, path doesn't resolve: a/b/c"`;modified:__tests__/base.js+12 added-16 removed
256 unmodified lines257 expect(() => {258 produce([], d => {259 d.x = 3260 })261- }).toThrow(262- "Immer only supports setting array indices and the 'length' property"263- )261+ }).toThrowErrorMatchingSnapshot()262 })263 264 it("throws when a non-numeric property is deleted", () => {265 expect(() => {1 unmodified line267 baseState.x = 7268 produce(baseState, d => {269 delete d.x270 })273- }).toThrow("Immer only supports deleting array indices")271+ }).toThrowErrorMatchingSnapshot()272 })273 }274 })275 58 unmodified lines334 if (useProxies) {335 s.modified = true336 }337 })340- }).toThrowError("Immer drafts cannot have computed properties")338+ }).toThrowErrorMatchingSnapshot()339 })340 341 it("allows inherited computed properties", () => {342 const proto = {}98 unmodified lines441 442 // NOTE: ES5 drafts only protect existing properties when revoked.443 it("revokes the draft once produce returns", () => {444 const expectRevoked = (fn, shouldThrow = true) => {447- if (shouldThrow) expect(fn).toThrowError(/revoked/)445+ if (shouldThrow) expect(fn).toThrowErrorMatchingSnapshot()446 else expect(fn).not.toThrow()447 }448 449 // Test object drafts:83 unmodified lines533 writeable: true,534 value: 2535 })536 })539- }).toThrow(540- "Object.defineProperty() cannot be used on an Immer draft"541- )537+ }).toThrowErrorMatchingSnapshot()538 })539 540 it("should handle constructor correctly", () => {541 const baseState = {146 unmodified lines688 689 if (useProxies)690 it("throws when Object.setPrototypeOf() is used on a draft", () => {691 produce({}, draft => {696- expect(() => Object.setPrototypeOf(draft, Array)).toThrow(697- "Object.setPrototypeOf() cannot be used on an Immer draft"698- )692+ expect(() =>693+ Object.setPrototypeOf(draft, Array)694+ ).toThrowErrorMatchingSnapshot()695 })696 })697 698 it("supports the 'in' operator", () => {106 unmodified lines805 produce(base, d => {806 d.a.b = 1807 return d.a808 })813- }).toThrow(/^An immer producer returned/)809+ }).toThrowErrorMatchingSnapshot()810 })811 812 it("can return a frozen object", () => {813 const res = deepFreeze([{x: 3}])21 unmodified lines835 const res = {}836 res.self = res837 expect(() => {838 produce(res, () => res.self)843- }).toThrow("Immer forbids circular references")839+ }).toThrowErrorMatchingSnapshot()840 })841 })842 843 // TODO: rewrite tests with async/await once node 6 support is dropped24 unmodified lines868 throw "failed"869 },870 e => {871 expect(e).toBe(err)876- expect(() => draft.a).toThrowError(/revoked/)872+ expect(() => draft.a).toThrowErrorMatchingSnapshot()873 }874 )875 })876 28 unmodified lines905 produce(base, draft => {906 draft.x = 4907 return {x: 5}908 })913- }).toThrow(/An immer producer returned a new value/)909+ }).toThrowErrorMatchingSnapshot()910 })911 912 it("should fix #117 - 1", () => {913 const reducer = (state, action) =>304 unmodified linesmodified:__tests__/curry.js+6 added-8 removed
7 unmodified lines89101112131415161718191213141516171819202156 unmodified lines7 unmodified lines describe("curry - " + name, () => { setUseProxies(useProxies)
it("should check arguments", () => { let error = /if first argument is not a function, the second argument to produce should be a function/ expect(() => produce()).toThrow(error) expect(() => produce({})).toThrow(error)
expect(() => produce({}, {})).toThrow(/should be a function/) expect(() => produce({}, () => {}, [])).toThrow( /third argument of a producer/ ) expect(() => produce()).toThrowErrorMatchingSnapshot() expect(() => produce({})).toThrowErrorMatchingSnapshot() expect(() => produce({}, {})).toThrowErrorMatchingSnapshot() expect(() => produce({}, () => {}, []) ).toThrowErrorMatchingSnapshot() })
it("should support currying", () => { const state = [{}, {}, {}]56 unmodified linesmodified:__tests__/patch.js+3 added-3 removed
59 unmodified lines60 it('throws when `op` is not "add", "replace", nor "remove"', () => {61 expect(() => {62 const patch = {op: "copy", from: [0], path: [1]}63 applyPatches([2], [patch])64- }).toThrowError(/^Unsupported patch operation:/)64+ }).toThrowErrorMatchingSnapshot()65 })66 it("throws when `path` cannot be resolved", () => {67 // missing parent68 expect(() => {69 const patch = {op: "add", path: ["a", "b"], value: 1}70 applyPatches({}, [patch])71- }).toThrowError(/^Cannot apply patch, path doesn't resolve:/)71+ }).toThrowErrorMatchingSnapshot()72 73 // missing grand-parent74 expect(() => {75 const patch = {op: "add", path: ["a", "b", "c"], value: 1}76 applyPatches({}, [patch])77- }).toThrowError(/^Cannot apply patch, path doesn't resolve:/)77+ }).toThrowErrorMatchingSnapshot()78 })79 })80 81 describe("simple assignment - 1", () => {341 unmodified lines