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

Function testPatches

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

Source from the content-addressed store, hash-verified

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

Callers 1

jsonpatch.test.tsFile · 0.70

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…