Skip to content

Commit

Permalink
feat(react): added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Aug 16, 2021
1 parent 7825ddd commit 135e445
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/react/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
3 changes: 3 additions & 0 deletions packages/react/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
};
2 changes: 1 addition & 1 deletion packages/react/src/useClassName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useClassNames<Key extends string>(styles: Record<Key, Style>) {
return classes as Record<Key, string>;
}

export function useClassName(style: Style = {}) {
export function useClassName(style: Style) {
const classes = useClassNames({ component: style });

return classes.component;
Expand Down
29 changes: 29 additions & 0 deletions packages/react/tests/useClassName.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { morfeo } from '@morfeo/web';
import { render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import { useClassName } from '../src';

const theme = {
colors: {
primary: 'black',
},
} as any;

morfeo.setTheme('default', theme);

beforeEach(() => {
morfeo.useTheme('default');
});

test('should apply the style with the className generated by `useClassName`', async () => {
const { result } = renderHook(() => useClassName({ bg: 'primary' }));
const { getByTestId } = render(
<button className={result.current} data-testid="button" />,
);
const button = getByTestId('button');

expect(button).toHaveStyle(
`background-color: ${morfeo.getTheme()['colors']['primary']}`,
);
});

0 comments on commit 135e445

Please sign in to comment.