Skip to content

Commit

Permalink
test(TableToolbar): update test to RTL (#13169)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
alisonjoseph and andreancardona authored Feb 23, 2023
1 parent 55c8201 commit dba4de9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,43 @@
*/

import React from 'react';
import { mount } from 'enzyme';
import { TableToolbar } from '../';
import TableToolbar from '../TableToolbar';
import { render, screen } from '@testing-library/react';

describe('DataTable.TableToolbar', () => {
it('should render', () => {
const wrapper = mount(<TableToolbar className="custom-class" />);
expect(wrapper).toMatchSnapshot();
describe('TableToolbar', () => {
describe('renders as expected - Component API', () => {
it('should render', () => {
const { container } = render(<TableToolbar />);

expect(container).toMatchSnapshot();
});

it('should spread extra props onto outermost element', () => {
const { container } = render(<TableToolbar data-testid="test-id" />);

expect(container.firstChild).toHaveAttribute('data-testid', 'test-id');
});

it('should respect aria-label prop', () => {
render(<TableToolbar aria-label="Aria label" />);

expect(screen.getByLabelText('Aria label')).toBeInTheDocument();
});

it('should render children as expected', () => {
render(
<TableToolbar>
<div>child</div>
</TableToolbar>
);

expect(screen.getByText('child')).toBeInTheDocument();
});

it('should respect size prop', () => {
const { container } = render(<TableToolbar size="sm" />);

expect(container.firstChild).toHaveClass('cds--table-toolbar--sm');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DataTable.TableToolbar should render 1`] = `
<TableToolbar
aria-label="data table toolbar"
className="custom-class"
>
exports[`TableToolbar renders as expected - Component API should render 1`] = `
<div>
<section
aria-label="data table toolbar"
className="cds--table-toolbar"
class="cds--table-toolbar"
/>
</TableToolbar>
</div>
`;

0 comments on commit dba4de9

Please sign in to comment.