Skip to content
Myr

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

2 files+148 added−3 removed

modified:__tests__/__snapshots__/base.js.snap+146 added
52 unmodified lines
53exports[`base functionality - es5 (no freeze) throws on computed properties 1`] = `"Invariant failed: Immer drafts cannot have computed properties"`;5455exports[`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."`;5657exports[`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}"`;5859exports[`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."`;6061exports[`base functionality - es5 (patch listener) recipe functions cannot return an object that references itself 1`] = `"Invariant failed: Immer forbids circular references"`;6263exports[`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}"`;6465exports[`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}"`;6667exports[`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]"`;6869exports[`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]"`;7071exports[`base functionality - es5 (patch listener) throws on computed properties 1`] = `"Invariant failed: Immer drafts cannot have computed properties"`;7273exports[`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."`;7475exports[`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"`;7677exports[`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 lines
173exports[`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"`;174175exports[`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."`;176177exports[`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"`;178179exports[`base functionality - proxy (patch listener) array drafts throws when a non-numeric property is deleted 1`] = `"Invariant failed: Immer only supports deleting array indices"`;180181exports[`base functionality - proxy (patch listener) async recipe function works with rejected promises 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;182183exports[`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."`;184185exports[`base functionality - proxy (patch listener) recipe functions cannot return an object that references itself 1`] = `"Invariant failed: Immer forbids circular references"`;186187exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 1`] = `"Cannot perform 'get' on a proxy that has been revoked"`;188189exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 2`] = `"Cannot perform 'set' on a proxy that has been revoked"`;190191exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 3`] = `"Cannot perform 'get' on a proxy that has been revoked"`;192193exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 4`] = `"Cannot perform 'set' on a proxy that has been revoked"`;194195exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 5`] = `"Cannot perform 'get' on a proxy that has been revoked"`;196197exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 6`] = `"Cannot perform 'set' on a proxy that has been revoked"`;198199exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 7`] = `"Cannot perform 'get' on a proxy that has been revoked"`;200201exports[`base functionality - proxy (patch listener) revokes the draft once produce returns 8`] = `"Cannot perform 'set' on a proxy that has been revoked"`;202203exports[`base functionality - proxy (patch listener) throws on computed properties 1`] = `"Invariant failed: Immer drafts cannot have computed properties"`;204205exports[`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"`;206207exports[`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"`;208209exports[`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."`;210211exports[`complex nesting map / set / object modify deep object 1`] = `212Object {213 "map": Map {214 "set1" => Set {
273 unmodified lines
488 },489 },490]491`;492493exports[`complex nesting map / set / object modify deep object 13`] = `494Object {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`;512513exports[`complex nesting map / set / object modify deep object 14`] = `514Array [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`;539540exports[`complex nesting map / set / object modify deep object 15`] = `541Object {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`;559560exports[`complex nesting map / set / object modify deep object 16`] = `561Array [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 lines
21})2223runBaseTest("proxy (no freeze)", true, false)24runBaseTest("proxy (autofreeze)", true, true)25runBaseTest("proxy (patch listener)", true, false, true)26runBaseTest("proxy (autofreeze)(patch listener)", true, true, true)26// runBaseTest("proxy (patch listener)", true, ufalse, true)2728// TODO: no freeze + patch28runBaseTest("es5 (no freeze)", false, false)29runBaseTest("es5 (autofreeze)", false, true)30runBaseTest("es5 (patch listener)", false, false, true)31runBaseTest("es5 (autofreeze)(patch listener)", false, true, true)32// TODO: no freeze + patch3233function runBaseTest(name, useProxies, autoFreeze, useListener) {34 const listener = useListener ? function() {} : undefined35 const {produce, produceWithPatches} = createPatchedImmer({
2067 unmodified lines