added base tests for autofreeze + patch listeners
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 67ab3ab · Browse files · 2 files·+148 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+148 added−3 removed
- tests:+148 added−3 removed
Provenance
- Commit
9f07525- Tree
1b1d359- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
67ab3ab
2 files changed+148 added−3 removed
modified:__tests__/__snapshots__/base.js.snap+146 added
52 unmodified lines53 exports[`base functionality - es5 (no freeze) throws on computed properties 1`] = `"Invariant failed: 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`] = `"Invariant failed: 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 - es5 (patch listener) async recipe function works with rejected promises 1`] = `"Invariant failed: 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}"`;58+59+exports[`base functionality - es5 (patch listener) recipe functions cannot return a modified child draft 1`] = `"Invariant failed: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;60+61+exports[`base functionality - es5 (patch listener) recipe functions cannot return an object that references itself 1`] = `"Invariant failed: Immer forbids circular references"`;62+63+exports[`base functionality - es5 (patch listener) revokes the draft once produce returns 1`] = `"Invariant failed: Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;64+65+exports[`base functionality - es5 (patch listener) revokes the draft once produce returns 2`] = `"Invariant failed: Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? {\\"a\\":1}"`;66+67+exports[`base functionality - es5 (patch listener) revokes the draft once produce returns 3`] = `"Invariant failed: Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;68+69+exports[`base functionality - es5 (patch listener) revokes the draft once produce returns 4`] = `"Invariant failed: Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? [1]"`;70+71+exports[`base functionality - es5 (patch listener) throws on computed properties 1`] = `"Invariant failed: Immer drafts cannot have computed properties"`;72+73+exports[`base functionality - es5 (patch listener) throws when the draft is modified and another object is returned 1`] = `"Invariant failed: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;74+75 exports[`base functionality - proxy (autofreeze) array drafts throws when a non-numeric property is added 1`] = `"Invariant failed: Immer only supports setting array indices and the 'length' property"`;76 77 exports[`base functionality - proxy (autofreeze) array drafts throws when a non-numeric property is deleted 1`] = `"Invariant failed: Immer only supports deleting array indices"`;78 94 unmodified lines173 exports[`base functionality - proxy (no freeze) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Invariant failed: Object.setPrototypeOf() cannot be used on an Immer draft"`;174 175 exports[`base functionality - proxy (no freeze) throws when the draft is modified and another object is returned 1`] = `"Invariant failed: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;176 177+exports[`base functionality - proxy (patch listener) array drafts throws when a non-numeric property is added 1`] = `"Invariant failed: Immer only supports setting array indices and the 'length' property"`;178+179+exports[`base functionality - proxy (patch listener) array drafts throws when a non-numeric property is deleted 1`] = `"Invariant failed: Immer only supports deleting array indices"`;180+181+exports[`base functionality - proxy (patch listener) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;182+183+exports[`base functionality - proxy (patch listener) recipe functions cannot return a modified child draft 1`] = `"Invariant failed: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;184+185+exports[`base functionality - proxy (patch listener) recipe functions cannot return an object that references itself 1`] = `"Invariant failed: Immer forbids circular references"`;186+187+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;188+189+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;190+191+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;192+193+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;194+195+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;196+197+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;198+199+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;200+201+exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;202+203+exports[`base functionality - proxy (patch listener) throws on computed properties 1`] = `"Invariant failed: Immer drafts cannot have computed properties"`;204+205+exports[`base functionality - proxy (patch listener) throws when Object.defineProperty() is used on drafts 1`] = `"Invariant failed: Object.defineProperty() cannot be used on an Immer draft"`;206+207+exports[`base functionality - proxy (patch listener) throws when Object.setPrototypeOf() is used on a draft 1`] = `"Invariant failed: Object.setPrototypeOf() cannot be used on an Immer draft"`;208+209+exports[`base functionality - proxy (patch listener) throws when the draft is modified and another object is returned 1`] = `"Invariant failed: An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft."`;210+211 exports[`complex nesting map / set / object modify deep object 1`] = `212 Object {213 "map": Map {214 "set1" => Set {273 unmodified lines488 },489 },490 ]491 `;492+493+exports[`complex nesting map / set / object modify deep object 13`] = `494+Object {495+ "map": Map {496+ "set1" => Set {497+ Object {498+ "a": 2,499+ },500+ Object {501+ "b": 2,502+ },503+ },504+ "set2" => Set {505+ Object {506+ "c": 3,507+ },508+ },509+ },510+}511+`;512+513+exports[`complex nesting map / set / object modify deep object 14`] = `514+Array [515+ Object {516+ "op": "remove",517+ "path": Array [518+ "map",519+ "set1",520+ 0,521+ ],522+ "value": Object {523+ "a": 1,524+ },525+ },526+ Object {527+ "op": "add",528+ "path": Array [529+ "map",530+ "set1",531+ 0,532+ ],533+ "value": Object {534+ "a": 2,535+ },536+ },537+]538+`;539+540+exports[`complex nesting map / set / object modify deep object 15`] = `541+Object {542+ "map": Map {543+ "set1" => Set {544+ Object {545+ "a": 2,546+ },547+ Object {548+ "b": 2,549+ },550+ },551+ "set2" => Set {552+ Object {553+ "c": 3,554+ },555+ },556+ },557+}558+`;559+560+exports[`complex nesting map / set / object modify deep object 16`] = `561+Array [562+ Object {563+ "op": "remove",564+ "path": Array [565+ "map",566+ "set1",567+ 0,568+ ],569+ "value": Object {570+ "a": 1,571+ },572+ },573+ Object {574+ "op": "add",575+ "path": Array [576+ "map",577+ "set1",578+ 0,579+ ],580+ "value": Object {581+ "a": 2,582+ },583+ },584+]585+`;modified:__tests__/base.js+2 added-3 removed
20 unmodified lines21 })22 23 runBaseTest("proxy (no freeze)", true, false)24 runBaseTest("proxy (autofreeze)", true, true)25+runBaseTest("proxy (patch listener)", true, false, true)26 runBaseTest("proxy (autofreeze)(patch listener)", true, true, true)26-// runBaseTest("proxy (patch listener)", true, ufalse, true)27 28-// TODO: no freeze + patch28 runBaseTest("es5 (no freeze)", false, false)29 runBaseTest("es5 (autofreeze)", false, true)30+runBaseTest("es5 (patch listener)", false, false, true)31 runBaseTest("es5 (autofreeze)(patch listener)", false, true, true)32-// TODO: no freeze + patch32 33 function runBaseTest(name, useProxies, autoFreeze, useListener) {34 const listener = useListener ? function() {} : undefined35 const {produce, produceWithPatches} = createPatchedImmer({2067 unmodified lines