Skip to content
Myr

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

7 files+212 added−37 removed

added:__tests__/__snapshots__/base.js.snap+157 added
1// Jest Snapshot v1, https://goo.gl/fbAQLP23exports[`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}"`;45exports[`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."`;67exports[`base functionality - es5 (autofreeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;89exports[`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}"`;1011exports[`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}"`;1213exports[`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]"`;1415exports[`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]"`;1617exports[`base functionality - es5 (autofreeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;1819exports[`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."`;2021exports[`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}"`;2223exports[`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."`;2425exports[`base functionality - es5 (autofreeze)(patch listener) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;2627exports[`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}"`;2829exports[`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}"`;3031exports[`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]"`;3233exports[`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]"`;3435exports[`base functionality - es5 (autofreeze)(patch listener) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;3637exports[`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."`;3839exports[`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}"`;4041exports[`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."`;4243exports[`base functionality - es5 (no freeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;4445exports[`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}"`;4647exports[`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}"`;4849exports[`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]"`;5051exports[`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]"`;5253exports[`base functionality - es5 (no freeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;5455exports[`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."`;5657exports[`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"`;5859exports[`base functionality - proxy (autofreeze) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;6061exports[`base functionality - proxy (autofreeze) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;6263exports[`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."`;6465exports[`base functionality - proxy (autofreeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;6667exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;6869exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;7071exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;7273exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;7475exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;7677exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;7879exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;8081exports[`base functionality - proxy (autofreeze) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;8283exports[`base functionality - proxy (autofreeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;8485exports[`base functionality - proxy (autofreeze) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;8687exports[`base functionality - proxy (autofreeze) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Object.setPrototypeOf() cannot be used on an Immer draft"`;8889exports[`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."`;9091exports[`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"`;9293exports[`base functionality - proxy (autofreeze)(patch listener) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;9495exports[`base functionality - proxy (autofreeze)(patch listener) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;9697exports[`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."`;9899exports[`base functionality - proxy (autofreeze)(patch listener) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;100101exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;102103exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;104105exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;106107exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;108109exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;110111exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;112113exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;114115exports[`base functionality - proxy (autofreeze)(patch listener) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;116117exports[`base functionality - proxy (autofreeze)(patch listener) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;118119exports[`base functionality - proxy (autofreeze)(patch listener) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;120121exports[`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"`;122123exports[`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."`;124125exports[`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"`;126127exports[`base functionality - proxy (no freeze) array drafts throws when a non-numeric property is deleted 1`] = `"Immer only supports deleting array indices"`;128129exports[`base functionality - proxy (no freeze) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;130131exports[`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."`;132133exports[`base functionality - proxy (no freeze) recipe functions cannot return an object that references itself 1`] = `"Immer forbids circular references"`;134135exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;136137exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;138139exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;140141exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;142143exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;144145exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;146147exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;148149exports[`base functionality - proxy (no freeze) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;150151exports[`base functionality - proxy (no freeze) throws on computed properties 1`] = `"Immer drafts cannot have computed properties"`;152153exports[`base functionality - proxy (no freeze) throws when Object.defineProperty() is used on drafts 1`] = `"Object.defineProperty() cannot be used on an Immer draft"`;154155exports[`base functionality - proxy (no freeze) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Object.setPrototypeOf() cannot be used on an Immer draft"`;156157exports[`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/fbAQLP23exports[`curry - es5 should check arguments 1`] = `"The first or second argument to \`produce\` must be a function"`;45exports[`curry - es5 should check arguments 2`] = `"The first or second argument to \`produce\` must be a function"`;67exports[`curry - es5 should check arguments 3`] = `"The first or second argument to \`produce\` must be a function"`;89exports[`curry - es5 should check arguments 4`] = `"The third argument to \`produce\` must be a function or undefined"`;1011exports[`curry - proxy should check arguments 1`] = `"The first or second argument to \`produce\` must be a function"`;1213exports[`curry - proxy should check arguments 2`] = `"The first or second argument to \`produce\` must be a function"`;1415exports[`curry - proxy should check arguments 3`] = `"The first or second argument to \`produce\` must be a function"`;1617exports[`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/fbAQLP23exports[`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}"`;45exports[`manual - es5 should check arguments 1`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;5exports[`manual - es5 should check arguments 1`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;67exports[`manual - es5 should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;7exports[`manual - es5 should check arguments 2`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;89exports[`manual - es5 should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;9exports[`manual - es5 should check arguments 3`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;1011exports[`manual - es5 should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;11exports[`manual - es5 should not finish drafts from produce 1`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;1213exports[`manual - es5 should not finish twice 1`] = `"The draft provided was has already been finished"`;13exports[`manual - es5 should not finish twice 1`] = `"The given draft is already finalized"`;1415exports[`manual - es5 should support patches drafts 1`] = `16Array [17 Array [
33 unmodified lines
51`;5253exports[`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}"`;5455exports[`manual - proxy should check arguments 1`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;55exports[`manual - proxy should check arguments 1`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;5657exports[`manual - proxy should check arguments 2`] = `"First argument to createDraft should be a plain object, an array, or an immerable object."`;57exports[`manual - proxy should check arguments 2`] = `"First argument to \`createDraft\` must be a plain object, an array, or an immerable object"`;5859exports[`manual - proxy should check arguments 3`] = `"First argument to finishDraft should be an object from createDraft."`;59exports[`manual - proxy should check arguments 3`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;6061exports[`manual - proxy should not finish drafts from produce 1`] = `"The draft provided was not created using \`createDraft\`"`;61exports[`manual - proxy should not finish drafts from produce 1`] = `"First argument to \`finishDraft\` must be a draft returned by \`createDraft\`"`;6263exports[`manual - proxy should not finish twice 1`] = `"The draft provided was has already been finished"`;63exports[`manual - proxy should not finish twice 1`] = `"The given draft is already finalized"`;6465exports[`manual - proxy should support patches drafts 1`] = `66Array [67 Array [
34 unmodified lines
added:__tests__/__snapshots__/patch.js.snap+7 added
1// Jest Snapshot v1, https://goo.gl/fbAQLP23exports[`applyPatches throws when \`op\` is not "add", "replace", nor "remove" 1`] = `"Unsupported patch operation: copy"`;45exports[`applyPatches throws when \`path\` cannot be resolved 1`] = `"Cannot apply patch, path doesn't resolve: a/b"`;67exports[`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 lines
257 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 })263264 it("throws when a non-numeric property is deleted", () => {265 expect(() => {
1 unmodified line
267 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 lines
334 if (useProxies) {335 s.modified = true336 }337 })340 }).toThrowError("Immer drafts cannot have computed properties")338 }).toThrowErrorMatchingSnapshot()339 })340341 it("allows inherited computed properties", () => {342 const proto = {}
98 unmodified lines
441442 // 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 }448449 // Test object drafts:
83 unmodified lines
533 writeable: true,534 value: 2535 })536 })539 }).toThrow(540 "Object.defineProperty() cannot be used on an Immer draft"541 )537 }).toThrowErrorMatchingSnapshot()538 })539540 it("should handle constructor correctly", () => {541 const baseState = {
146 unmodified lines
688689 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 })697698 it("supports the 'in' operator", () => {
106 unmodified lines
805 produce(base, d => {806 d.a.b = 1807 return d.a808 })813 }).toThrow(/^An immer producer returned/)809 }).toThrowErrorMatchingSnapshot()810 })811812 it("can return a frozen object", () => {813 const res = deepFreeze([{x: 3}])
21 unmodified lines
835 const res = {}836 res.self = res837 expect(() => {838 produce(res, () => res.self)843 }).toThrow("Immer forbids circular references")839 }).toThrowErrorMatchingSnapshot()840 })841 })842843 // TODO: rewrite tests with async/await once node 6 support is dropped
24 unmodified lines
868 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 lines
905 produce(base, draft => {906 draft.x = 4907 return {x: 5}908 })913 }).toThrow(/An immer producer returned a new value/)909 }).toThrowErrorMatchingSnapshot()910 })911912 it("should fix #117 - 1", () => {913 const reducer = (state, action) =>
304 unmodified lines
modified:__tests__/curry.js+6 added-8 removed
modified:__tests__/patch.js+3 added-3 removed
59 unmodified lines
60 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()7273 // 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})8081describe("simple assignment - 1", () => {
341 unmodified lines