Skip to content

Commit

Permalink
chore: add tests for the style provider component
Browse files Browse the repository at this point in the history
  • Loading branch information
eels committed Oct 28, 2021
1 parent f223ebe commit 17c3554
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions test/core/ChicStyleProvider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ChicStyleProvider from '@src/core/ChicStyleProvider';
import StyleContext from '@src/lib/StyleContext';
import styles from '@test/__mocks__/styles.module.json';
import { createElement } from 'react';
import { render, screen } from '@testing-library/react';
import type { CSSModule } from '@types';

describe('core/ChicStyleProvider', () => {
it('should return a context provider that child components can read from', () => {
const Consumer = createElement(StyleContext.Consumer, null, (context: CSSModule) => {
return createElement('h1', null, context.hero);
});

render(createElement(ChicStyleProvider, { styles: styles }, Consumer));
expect(screen.getByRole('heading').innerHTML).toBe('hero');
});
});
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ChicTagWithAttrsInterface = {
};

export type ChicStyleProviderProps = {
children: ReactNode;
children?: ReactNode;
styles: CSSModule;
};

Expand Down

0 comments on commit 17c3554

Please sign in to comment.