MCPcopy
hub / github.com/mobxjs/mobx-state-tree / testPatches

Function testPatches

__tests__/core/recordPatches.test.ts:15–35  ·  view source on GitHub ↗
(
    type: IType<C, S, T>,
    snapshot: C,
    fn: any,
    expectedPatches: IJsonPatch[],
    expectedInversePatches: IJsonPatch[]
)

Source from the content-addressed store, hash-verified

13import { expect, test } from "bun:test"
14
15function testPatches<C, S, T extends object>(
16 type: IType<C, S, T>,
17 snapshot: C,
18 fn: any,
19 expectedPatches: IJsonPatch[],
20 expectedInversePatches: IJsonPatch[]
21) {
22 const instance = type.create(snapshot)
23 const baseSnapshot = getSnapshot(instance)
24 const recorder = recordPatches(instance)
25 unprotect(instance)
26 fn(instance)
27 recorder.stop()
28 expect(recorder.patches).toEqual(expectedPatches)
29 expect(recorder.inversePatches).toEqual(expectedInversePatches)
30 const clone = type.create(snapshot)
31 recorder.replay(clone)
32 expect(getSnapshot(clone)).toEqual(getSnapshot(instance))
33 recorder.undo()
34 expect(getSnapshot(instance)).toEqual(baseSnapshot)
35}
36const Node = types.model("Node", {
37 id: types.identifierNumber,
38 text: "Hi",

Callers 1

Calls 8

getSnapshotFunction · 0.90
recordPatchesFunction · 0.90
unprotectFunction · 0.90
fnFunction · 0.85
createMethod · 0.80
undoMethod · 0.80
stopMethod · 0.65
replayMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…