-
Notifications
You must be signed in to change notification settings - Fork 685
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
231dd6b
commit fd1ffb4
Showing
10 changed files
with
153 additions
and
322 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,70 +1,26 @@ | ||
import React from 'react'; | ||
import { configure, mount, shallow } from 'enzyme'; | ||
import { configure, shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import MagentoRouter, { Consumer as RouteConsumer } from '../Router'; | ||
import MagentoRouter from '../Router'; | ||
|
||
jest.mock('FETCH_ROOT_COMPONENT', () => jest.fn(), { virtual: true }); | ||
|
||
configure({ adapter: new Adapter() }); | ||
|
||
const apiBase = 'https://store.com'; | ||
|
||
const initialEntries = ['/some-product.html']; | ||
const routerProps = { initialEntries }; | ||
|
||
test('renders a single, catch-all route', () => { | ||
const routesWrapper = shallow( | ||
<MagentoRouter using={MemoryRouter} apiBase={apiBase} /> | ||
).find('Route'); | ||
expect(routesWrapper.length).toBe(1); | ||
expect(routesWrapper.prop('path')).toBeUndefined(); | ||
}); | ||
|
||
test('passes `config` and route props to context provider', () => { | ||
const fn = jest.fn(); | ||
const props = { apiBase, using: MemoryRouter }; | ||
test('calls render routes function', () => { | ||
const renderRoutesMock = jest.fn(); | ||
|
||
// we need to test context consumer, so we can't shallow render | ||
mount( | ||
<MagentoRouter {...props}> | ||
<RouteConsumer>{fn}</RouteConsumer> | ||
</MagentoRouter> | ||
shallow( | ||
<MagentoRouter | ||
using={MemoryRouter} | ||
apiBase={apiBase} | ||
renderRoutes={renderRoutesMock} | ||
/> | ||
); | ||
|
||
expect(fn).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
apiBase, | ||
history: expect.anything(), // from Route | ||
location: expect.anything(), // from Route | ||
match: expect.anything() // from Route | ||
}) | ||
); | ||
}); | ||
|
||
test('passes `routerProps` to router, not context provider', () => { | ||
const fn = jest.fn(); | ||
const props = { apiBase, routerProps, using: MemoryRouter }; | ||
|
||
// we need to test context consumer, so we can't shallow render | ||
const wrapper = mount( | ||
<MagentoRouter {...props}> | ||
<RouteConsumer>{fn}</RouteConsumer> | ||
</MagentoRouter> | ||
); | ||
|
||
expect(fn).toHaveBeenCalledWith( | ||
expect.not.objectContaining({ | ||
initialEntries: expect.anything() | ||
}) | ||
); | ||
expect(wrapper.find('Router').instance().props).toEqual( | ||
expect.objectContaining({}) | ||
); | ||
expect(fn).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
history: expect.objectContaining({ | ||
length: initialEntries.length | ||
}) | ||
}) | ||
); | ||
expect(renderRoutesMock).toBeCalled(); | ||
}); |
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,6 +1,6 @@ | ||
import React from 'react'; | ||
import ErrorView from 'src/components/ErrorView'; | ||
|
||
const renderRoutingError = props => <ErrorView { ...props } />; | ||
const renderRoutingError = props => <ErrorView {...props} />; | ||
|
||
export default renderRoutingError; |