-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into tests--description-list
- Loading branch information
Showing
3 changed files
with
37 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
44 changes: 21 additions & 23 deletions
44
...ests__/src/components/Breadcrumb/index.js → .../src/components/Breadcrumb/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,58 @@ | ||
import React, { createRef } from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { | ||
default as Breadcrumb, | ||
BreadcrumbLink, | ||
BreadcrumbItem | ||
} from 'src/components/Breadcrumb'; | ||
import axe from '../../../axe'; | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Breadcrumb, { BreadcrumbLink, BreadcrumbItem } from './'; | ||
import axe from '../../axe'; | ||
|
||
test('should render breadcrumbs', () => { | ||
const breadcrumb = shallow( | ||
render( | ||
<Breadcrumb aria-label="breadcrumb"> | ||
<BreadcrumbLink href="#">one</BreadcrumbLink> | ||
<BreadcrumbLink href="#">two</BreadcrumbLink> | ||
<BreadcrumbItem>three</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
expect(breadcrumb.hasClass('Breadcrumb')).toBe(true); | ||
expect(breadcrumb.find('li').length).toBe(3); | ||
expect( | ||
screen.getByRole('navigation', { name: 'breadcrumb' }) | ||
).toBeInTheDocument(); | ||
expect(screen.queryAllByRole('listitem')).toHaveLength(3); | ||
}); | ||
|
||
test('should render separators between breadcrumbs', () => { | ||
const breadcrumb = shallow( | ||
render( | ||
<Breadcrumb aria-label="breadcrumb"> | ||
<BreadcrumbLink href="#">one</BreadcrumbLink> | ||
<BreadcrumbLink href="#">two</BreadcrumbLink> | ||
<BreadcrumbItem>three</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
expect(breadcrumb.find('.Breadcrumb__Separator').length).toBe(2); | ||
expect( | ||
breadcrumb | ||
.find(BreadcrumbItem) | ||
.find('.Breadcrumb__Separator') | ||
.exists() | ||
).toBeFalsy(); | ||
screen.getByRole('navigation', { name: 'breadcrumb' }) | ||
).toHaveTextContent('one/two/three'); | ||
}); | ||
|
||
test('should render custom separators between breadcrumbs', () => { | ||
const breadcrumb = shallow( | ||
render( | ||
<Breadcrumb aria-label="breadcrumb" separator="💩"> | ||
<BreadcrumbLink href="#">one</BreadcrumbLink> | ||
<BreadcrumbLink href="#">two</BreadcrumbLink> | ||
<BreadcrumbItem>three</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
expect(breadcrumb.text()).toEqual('one💩two💩three'); | ||
expect( | ||
screen.getByRole('navigation', { name: 'breadcrumb' }) | ||
).toHaveTextContent('one💩two💩three'); | ||
}); | ||
|
||
test('should return no axe violations', async () => { | ||
const breadcrumb = shallow( | ||
render( | ||
<Breadcrumb aria-label="breadcrumb"> | ||
<BreadcrumbLink href="#">one</BreadcrumbLink> | ||
<BreadcrumbLink href="#">two</BreadcrumbLink> | ||
<BreadcrumbItem>three</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
|
||
expect(await axe(breadcrumb.html())).toHaveNoViolations(); | ||
const results = await axe( | ||
screen.getByRole('navigation', { name: 'breadcrumb' }) | ||
); | ||
expect(results).toHaveNoViolations(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import Line from './index'; | ||
import axe from '../../axe'; | ||
|
||
test('passes classNames through', () => { | ||
const { container } = render(<Line className="baz" />); | ||
expect(container.firstChild).toHaveClass('Line', 'baz'); | ||
}); | ||
|
||
test('should return no axe violations', async () => { | ||
const { container } = render(<Line />); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); |