-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abf4bfc
commit 9da5f81
Showing
1 changed file
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { withLocation, withNavigate } from './hoc'; | ||
|
||
const mockedNavigator = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useNavigate: () => mockedNavigator, | ||
useLocation: () => ({ | ||
pathname: '/current-location', | ||
}), | ||
})); | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const MockComponent = ({ navigate, location }) => ( | ||
// eslint-disable-next-line react/button-has-type, react/prop-types | ||
<button id="btn" onClick={() => navigate('/some-route')}>{location.pathname}</button> | ||
); | ||
const WrappedComponent = withNavigate(withLocation(MockComponent)); | ||
|
||
test('Provide Navigation to Component', () => { | ||
const wrapper = mount( | ||
<WrappedComponent />, | ||
); | ||
const btn = wrapper.find('#btn'); | ||
btn.simulate('click'); | ||
|
||
expect(mockedNavigator).toHaveBeenCalledWith('/some-route'); | ||
}); | ||
|
||
test('Provide Location object to Component', () => { | ||
const wrapper = mount( | ||
<WrappedComponent />, | ||
); | ||
|
||
expect(wrapper.find('#btn').text()).toContain('/current-location'); | ||
}); |