From 17d6abce550720a7a55df5b73cde0fd42d34e1ae Mon Sep 17 00:00:00 2001 From: Harry Brundage Date: Wed, 5 Jun 2024 18:46:33 +0000 Subject: [PATCH] Add failing test for missing snapshot processor node argument --- __tests__/core/snapshotProcessor.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/__tests__/core/snapshotProcessor.test.ts b/__tests__/core/snapshotProcessor.test.ts index 004e1a670..44e8ceae2 100644 --- a/__tests__/core/snapshotProcessor.test.ts +++ b/__tests__/core/snapshotProcessor.test.ts @@ -304,6 +304,30 @@ describe("snapshotProcessor", () => { // cloning expect(getSnapshot(clone(model.m))[0]).toBe(6) }) + + test("post processors on children are passed the node when the children are a model type", () => { + const child = types.model({ name: types.string }) + const Model = types.model({ + children: types.array( + types.snapshotProcessor(child, { + postProcessor(sn, node) { + expect(node).toBeDefined() + return { name: sn.name.toUpperCase() } + } + }) + ) + }) + + const model = Model.create({ + children: [{ name: "foo" }, { name: "bar" }] + }) + + unprotect(model) + expect(model.children[0].name).toBe("foo") + expect(model.children[1].name).toBe("bar") + expect(getSnapshot(model).children[0].name).toBe("FOO") + expect(getSnapshot(model).children[1].name).toBe("BAR") + }) }) describe("over a map type", () => {