-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: issue where modified attributes where not passed down * feat: migrate entire project to RTL * chore: remove enzyme files * chore: run lint and prettier
- Loading branch information
1 parent
6085ac0
commit 7ada175
Showing
21 changed files
with
494 additions
and
1,021 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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,30 +1,27 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { NavbarBrand } from '..'; | ||
import { | ||
testForChildrenInComponent, | ||
testForCustomClass, | ||
testForDefaultClass, | ||
testForDefaultTag, | ||
} from '../testUtils'; | ||
|
||
describe('NavbarBrand', () => { | ||
it('should render .navbar-brand markup', () => { | ||
const wrapper = shallow(<NavbarBrand />); | ||
|
||
expect(wrapper.html()).toBe('<a class="navbar-brand"></a>'); | ||
testForDefaultClass(NavbarBrand, 'navbar-brand'); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<NavbarBrand tag="div" />); | ||
|
||
expect(wrapper.html()).toBe('<div class="navbar-brand"></div>'); | ||
testForDefaultTag(NavbarBrand, 'a'); | ||
}); | ||
|
||
it('sholid render children', () => { | ||
const wrapper = shallow(<NavbarBrand>Children</NavbarBrand>); | ||
|
||
expect(wrapper.html()).toBe('<a class="navbar-brand">Children</a>'); | ||
testForChildrenInComponent(NavbarBrand); | ||
}); | ||
|
||
it('should pass additional classNames', () => { | ||
const wrapper = shallow(<NavbarBrand className="extra" />); | ||
|
||
expect(wrapper.hasClass('extra')).toBe(true); | ||
expect(wrapper.hasClass('navbar-brand')).toBe(true); | ||
testForCustomClass(NavbarBrand); | ||
}); | ||
}); |
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,78 +1,76 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { createEvent, fireEvent, render, screen } from '@testing-library/react'; | ||
import user from '@testing-library/user-event'; | ||
import { NavLink } from '..'; | ||
import { | ||
testForChildrenInComponent, | ||
testForCustomClass, | ||
testForCustomTag, | ||
testForDefaultClass, | ||
} from '../testUtils'; | ||
|
||
describe('NavLink', () => { | ||
it('should render .nav-link markup', () => { | ||
const wrapper = shallow(<NavLink />); | ||
|
||
expect(wrapper.html()).toBe('<a class="nav-link"></a>'); | ||
testForDefaultClass(NavLink, 'nav-link'); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = shallow(<NavLink tag="div" />); | ||
|
||
expect(wrapper.html()).toBe('<div class="nav-link"></div>'); | ||
testForCustomTag(NavLink); | ||
}); | ||
|
||
it('should render children', () => { | ||
const wrapper = shallow(<NavLink>Children</NavLink>); | ||
|
||
expect(wrapper.html()).toBe('<a class="nav-link">Children</a>'); | ||
testForChildrenInComponent(NavLink); | ||
}); | ||
|
||
it('should pass additional classNames', () => { | ||
const wrapper = shallow(<NavLink className="extra" />); | ||
|
||
expect(wrapper.hasClass('extra')).toBe(true); | ||
expect(wrapper.hasClass('nav-link')).toBe(true); | ||
testForCustomClass(NavLink); | ||
}); | ||
|
||
it('should render active class', () => { | ||
const wrapper = shallow(<NavLink active />); | ||
|
||
expect(wrapper.hasClass('active')).toBe(true); | ||
render(<NavLink active>Yo!</NavLink>); | ||
expect(screen.getByText('Yo!')).toHaveClass('active'); | ||
}); | ||
|
||
it('should render disabled markup', () => { | ||
const wrapper = shallow(<NavLink disabled />); | ||
|
||
expect(wrapper.hasClass('disabled')).toBe(true); | ||
render(<NavLink disabled>Yo!</NavLink>); | ||
expect(screen.getByText('Yo!')).toHaveAttribute('disabled'); | ||
}); | ||
|
||
it('handles onClick prop', () => { | ||
const onClick = jest.fn(); | ||
const e = createSpyObj('e', ['preventDefault']); | ||
const wrapper = shallow(<NavLink onClick={onClick} />); | ||
render(<NavLink onClick={onClick}>testing click</NavLink>); | ||
|
||
wrapper.find('a').simulate('click', e); | ||
user.click(screen.getByText(/testing click/i)); | ||
expect(onClick).toHaveBeenCalled(); | ||
expect(e.preventDefault).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('handles onClick events', () => { | ||
const e = createSpyObj('e', ['preventDefault']); | ||
const wrapper = shallow(<NavLink />); | ||
render(<NavLink>hello</NavLink>); | ||
const node = screen.getByText(/hello/i); | ||
const click = createEvent.click(node); | ||
fireEvent(node, click); | ||
|
||
wrapper.find('a').simulate('click', e); | ||
expect(e.preventDefault).not.toHaveBeenCalled(); | ||
expect(click.defaultPrevented).toBeFalsy(); | ||
}); | ||
|
||
it('prevents link clicks via onClick for dropdown nav-items', () => { | ||
const e = createSpyObj('e', ['preventDefault']); | ||
const wrapper = shallow(<NavLink href="#" />); | ||
render(<NavLink href="#">hello</NavLink>); | ||
const node = screen.getByText(/hello/i); | ||
const click = createEvent.click(node); | ||
fireEvent(node, click); | ||
|
||
wrapper.find('a').simulate('click', e); | ||
expect(e.preventDefault).toHaveBeenCalled(); | ||
expect(click.defaultPrevented).toBeTruthy(); | ||
}); | ||
|
||
it('is not called when disabled', () => { | ||
const onClick = jest.fn(); | ||
const e = createSpyObj('e', ['preventDefault']); | ||
const wrapper = shallow(<NavLink disabled onClick={onClick} />); | ||
render( | ||
<NavLink onClick={onClick} disabled> | ||
testing click | ||
</NavLink>, | ||
); | ||
|
||
wrapper.find('a').simulate('click', e); | ||
expect(e.preventDefault).toHaveBeenCalled(); | ||
user.click(screen.getByText(/testing click/i)); | ||
expect(onClick).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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,43 +1,47 @@ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { screen, render } from '@testing-library/react'; | ||
import { Pagination } from '..'; | ||
import { testForChildrenInComponent } from '../testUtils'; | ||
|
||
describe('Pagination', () => { | ||
it('should render "nav" tag by default', () => { | ||
const wrapper = mount(<Pagination />); | ||
|
||
expect(wrapper.find('nav').hostNodes().length).toBe(1); | ||
render(<Pagination data-testid="test" />); | ||
const node = screen.getByLabelText('pagination'); | ||
expect(node.tagName.toLowerCase()).toMatch('nav'); | ||
}); | ||
|
||
it('should render default list tag', () => { | ||
const wrapper = mount(<Pagination />); | ||
|
||
expect(wrapper.children().find('ul').hostNodes().length).toBe(1); | ||
render(<Pagination />); | ||
expect( | ||
screen.getByLabelText('pagination').querySelector('ul'), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = mount(<Pagination tag="main" />); | ||
|
||
expect(wrapper.find('main').hostNodes().length).toBe(1); | ||
render(<Pagination tag="main" />); | ||
expect(screen.getByLabelText('pagination').tagName.toLowerCase()).toBe( | ||
'main', | ||
); | ||
}); | ||
|
||
it('should render with "pagination" class', () => { | ||
const wrapper = shallow(<Pagination />); | ||
|
||
expect(wrapper.children().hasClass('pagination')).toBe(true); | ||
render(<Pagination data-testid="pagination" />); | ||
expect(screen.getByTestId('pagination')).toHaveClass('pagination'); | ||
}); | ||
|
||
it('should render children', () => { | ||
const wrapper = shallow(<Pagination>Ello world</Pagination>); | ||
|
||
expect(wrapper.text()).toBe('Ello world'); | ||
testForChildrenInComponent(Pagination); | ||
}); | ||
|
||
it('should render pagination at different sizes', () => { | ||
const small = shallow(<Pagination size="sm" />); | ||
const large = shallow(<Pagination size="lg" />); | ||
describe('should render pagination at different sizes', () => { | ||
it('should render with sm', () => { | ||
render(<Pagination size="sm" data-testid="pagination" />); | ||
expect(screen.getByTestId('pagination')).toHaveClass('pagination-sm'); | ||
}); | ||
|
||
expect(small.children().hasClass('pagination-sm')).toBe(true); | ||
expect(large.children().hasClass('pagination-lg')).toBe(true); | ||
it('should render lg', () => { | ||
render(<Pagination size="lg" data-testid="pagination" />); | ||
expect(screen.getByTestId('pagination')).toHaveClass('pagination-lg'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.