Skip to content

Instantly share code, notes, and snippets.

@codegino
Created November 30, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegino/a7fba3de24b4414c00ecf1090acaaf18 to your computer and use it in GitHub Desktop.
Save codegino/a7fba3de24b4414c00ecf1090acaaf18 to your computer and use it in GitHub Desktop.
Testing Improvement
import {render,fireEvent} from './custom-rtl'
describe('Outlined Button', (): void => {
test('Size of button should render correctly for variant outlined', (): void => {
const { container } = render(
<ButtonOutlined color="grey">
<SvgClose /> Text does not matter
</ButtonOutlined>
);
expect(container.firstChild).toHaveStyleRule('min-height', '2.25rem');
});
});
test('Button component should pass down an onClick function', (): void => {
const testClick = jest.fn();
const { getByText } = render(<ButtonText onClick={testClick}>Click Me</ButtonText>);
fireEvent.click(getByText(/Click Me/i));
expect(testClick).toHaveBeenCalled();
});
import React from 'react';
import { render as rtlRender } from '@testing-library/react';
import NdsThemeProvider from '../../Theme/NdsThemeProvider';
function render(ui, {theme='blue', ...options} = {}) {
const Wrapper = ({children}) => (
<NdsThemeProvider theme={theme}>{children}</NdsThemeProvider>
)
return rtlRender(ui, {wrapper: Wrapper, ...options})
}
export * from '@testing-library/react';
// override all test with our custom render function
export { render };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment