Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Fixing null/undefined theme argument for the WordPressBlocksProvider #2013

Open
wants to merge 12 commits into
base: canary
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function WordPressBlocksProvider(props: {
config: WordPressBlocksProviderConfig;
}) {
const { children, config } = props;
const { blocks, theme } = config;
const { blocks, theme = {} } = config;

return (
<WordPressBlocksContext.Provider value={blocks}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import type { BlocksTheme } from '../../src/types/theme';
import { renderHook } from '@testing-library/react'; // Import from @testing-library/react

describe('useBlocksTheme', () => {
it('Throws an error if not used within WordPressBlocksProvider', () => {
// Assert that renderHook throws an error when used outside of WordPressBlocksProvider
expect(() => {
renderHook(() => useBlocksTheme());
}).toThrow('useBlocksTheme hook was called outside of context, make sure your app is wrapped with WordPressBlocksProvider');
});

it('returns the passed in theme from WordPressBlocksProvider', () => {
// Wrapping component to provide context
const wrapper = ({ children }: PropsWithChildren<{}>) => {
Expand Down Expand Up @@ -46,4 +39,4 @@ describe('useBlocksTheme', () => {
// Check the correct theme is returned
expect(theme?.colors?.palette).toStrictEqual({ primary: 'black' });
});
});
});
Loading