Skip to content

Commit

Permalink
chore(UnorderedList): refactor to rtl tests (#10387)
Browse files Browse the repository at this point in the history
* chore(UnorderedList): refactor to rtl tests

* Update packages/react/src/components/UnorderedList/UnorderedList-test.js

Co-authored-by: Josh Black <[email protected]>

* Update packages/react/src/components/UnorderedList/UnorderedList-test.js

Co-authored-by: Josh Black <[email protected]>

* Update packages/react/src/components/UnorderedList/UnorderedList-test.js

Co-authored-by: Josh Black <[email protected]>

* chore: empty commit

* chore: fix format

Co-authored-by: Josh Black <[email protected]>
  • Loading branch information
jnm2377 and joshblack authored Jan 14, 2022
1 parent 8c353ed commit e95d6ad
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions packages/react/src/components/UnorderedList/UnorderedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,43 @@
import React from 'react';
import UnorderedList from '../UnorderedList';
import ListItem from '../ListItem';
import { shallow } from 'enzyme';
import { settings } from 'carbon-components';
import { render, screen } from '@testing-library/react';

const { prefix } = settings;

describe('UnorderedList', () => {
describe('Renders as expected', () => {
const list = shallow(
<UnorderedList className="some-class">
it('should render children as expected', () => {
render(
<UnorderedList>
<ListItem>Item</ListItem>
</UnorderedList>
);
expect(screen.getByText('Item')).toBeInTheDocument();
});

it('should be a ul element', () => {
expect(list.find('ul').length).toEqual(1);
});
it('should render nested lists', () => {
render(
<UnorderedList>
<ListItem>Item</ListItem>
<UnorderedList nested data-testid="nested-list">
<ListItem>Nested</ListItem>
</UnorderedList>
</UnorderedList>
);

it('should render with the appropriate classes', () => {
expect(list.hasClass(`${prefix}--list--unordered`)).toEqual(true);
expect(list.hasClass('some-class')).toEqual(true);
});
expect(screen.getByTestId('nested-list')).toHaveClass(
`${prefix}--list--nested`
);
});

it('should render children as expected', () => {
expect(list.find(ListItem).length).toEqual(1);
});
it('should add custom className given via className prop', () => {
render(
<UnorderedList className="some-class" data-testid="list">
<ListItem>Item</ListItem>
</UnorderedList>
);

it('should render nested lists', () => {
list.setProps({ nested: true });
expect(list.hasClass(`${prefix}--list--nested`)).toEqual(true);
list.setProps({ nested: false });
expect(list.hasClass(`${prefix}--list--nested`)).toEqual(false);
});
expect(screen.getByTestId('list')).toHaveClass('some-class');
});
});

0 comments on commit e95d6ad

Please sign in to comment.