From 66de140423bb0abe78290af4535bf18ed8579e4c Mon Sep 17 00:00:00 2001 From: Kim Ode Date: Tue, 6 Feb 2024 02:29:35 +0100 Subject: [PATCH] Fix missing fail import (#2137) * Fix missing fail import * Add test case for incorrect processor * Only run test in dev --- __tests__/core/snapshotProcessor.test.ts | 12 ++++++++++++ src/types/utility-types/snapshotProcessor.ts | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/__tests__/core/snapshotProcessor.test.ts b/__tests__/core/snapshotProcessor.test.ts index 96b1d30ff..2b427852f 100644 --- a/__tests__/core/snapshotProcessor.test.ts +++ b/__tests__/core/snapshotProcessor.test.ts @@ -843,4 +843,16 @@ describe("snapshotProcessor", () => { expect(() => store.setProp("b")).not.toThrow() expect(store.prop).toBe("b") }) + + if (process.env.NODE_ENV !== "production") { + test("it should fail if given incorrect processor", () => { + expect(() => { + types.model({ + m: types.snapshotProcessor(types.number, { + postProcessor: {} as any + }) + }) + }).toThrowError("[mobx-state-tree] postSnapshotProcessor must be a function") + }) + } }) diff --git a/src/types/utility-types/snapshotProcessor.ts b/src/types/utility-types/snapshotProcessor.ts index ac0d16566..0712bbc1b 100644 --- a/src/types/utility-types/snapshotProcessor.ts +++ b/src/types/utility-types/snapshotProcessor.ts @@ -16,7 +16,8 @@ import { typeCheckFailure, isUnionType, Instance, - ObjectNode + ObjectNode, + fail } from "../../internal" /** @hidden */