(
type: IType<C, S, T>,
snapshot: C,
fn: any,
expectedPatches: IJsonPatch[]
)
| 18 | import { expect, test } from "bun:test" |
| 19 | |
| 20 | function 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 | } |
| 39 | const Node = types.model("Node", { |
| 40 | id: types.identifierNumber, |
| 41 | text: "Hi", |
no test coverage detected
searching dependent graphs…