Skip to content

Commit

Permalink
fix: checking for correct resolver value in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ismajl-ramadani committed Oct 4, 2023
1 parent 462d368 commit c858d9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const Editor: React.FC<React.PropsWithChildren<Partial<Options>>> = ({
// 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
);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/editor/tests/editor.test.tsx
Original file line number Diff line number Diff line change
@@ -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 <Editor /> with resolvers that are not valid objects', () => {
expect(() => {
const resolver = (null as unknown) as Resolver;
render(<Editor resolver={resolver} />);
}).toThrowError(ERROR_RESOLVER_NOT_AN_OBJECT);
});
});

0 comments on commit c858d9e

Please sign in to comment.