From c858d9ee19abe048685e062b0fbc6d5dce29a695 Mon Sep 17 00:00:00 2001 From: ismajl-ramadani Date: Wed, 4 Oct 2023 12:14:29 +0200 Subject: [PATCH] fix: checking for correct resolver value in editor --- packages/core/src/editor/Editor.tsx | 4 +++- packages/core/src/editor/tests/editor.test.tsx | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/core/src/editor/tests/editor.test.tsx diff --git a/packages/core/src/editor/Editor.tsx b/packages/core/src/editor/Editor.tsx index f00666bc0..a0d3a6cc3 100644 --- a/packages/core/src/editor/Editor.tsx +++ b/packages/core/src/editor/Editor.tsx @@ -18,7 +18,9 @@ export const Editor: React.FC>> = ({ // we do not want to warn the user if no resolver was supplied if (options.resolver !== undefined) { invariant( - typeof options.resolver === 'object' && !Array.isArray(options.resolver), + typeof options.resolver === 'object' && + !Array.isArray(options.resolver) && + options.resolver !== null, ERROR_RESOLVER_NOT_AN_OBJECT ); } diff --git a/packages/core/src/editor/tests/editor.test.tsx b/packages/core/src/editor/tests/editor.test.tsx new file mode 100644 index 000000000..74b999fd2 --- /dev/null +++ b/packages/core/src/editor/tests/editor.test.tsx @@ -0,0 +1,15 @@ +import { ERROR_RESOLVER_NOT_AN_OBJECT } from '@craftjs/utils'; +import { render } from '@testing-library/react'; +import * as React from 'react'; + +import { Resolver } from '../../interfaces'; +import { Editor } from '../Editor'; + +describe('Editor Component', () => { + it('should throw an error when we use with resolvers that are not valid objects', () => { + expect(() => { + const resolver = (null as unknown) as Resolver; + render(); + }).toThrowError(ERROR_RESOLVER_NOT_AN_OBJECT); + }); +});