Skip to content

Instantly share code, notes, and snippets.

@alpavlove
Created August 18, 2022 13:31
Show Gist options
  • Save alpavlove/4ec632a2344ee7e3a161ab21a45e2095 to your computer and use it in GitHub Desktop.
Save alpavlove/4ec632a2344ee7e3a161ab21a45e2095 to your computer and use it in GitHub Desktop.
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('disabled', () => {
const { asFragment } = render(
<Button onClick={console.log} isDisabled={true}>
Click me
</Button>
);
expect(asFragment()).toMatchInlineSnapshot(`
<DocumentFragment>
<button
class="button button-primary"
disabled=""
>
Click me
</button>
</DocumentFragment>
`);
});
// test('should be clickable', () => {});
// test('should not be clickable if disabled', () => {});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment