(
type: IType<C, S, T>,
snapshot: C,
fn: any,
expectedPatches: IJsonPatch[],
expectedInversePatches: IJsonPatch[]
)
| 13 | import { expect, test } from "bun:test" |
| 14 | |
| 15 | function 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 | } |
| 36 | const Node = types.model("Node", { |
| 37 | id: types.identifierNumber, |
| 38 | text: "Hi", |
no test coverage detected
searching dependent graphs…