-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for server/RouterProvider.js
- Loading branch information
1 parent
fbe56f4
commit e99b394
Showing
1 changed file
with
63 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,63 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import RouterProvider from '../../src/server/RouterProvider'; | ||
import { routerShape } from '../../src/PropTypes'; | ||
|
||
const router = { | ||
push: jest.fn(), | ||
replace: jest.fn(), | ||
go: jest.fn(), | ||
createHref: jest.fn(), | ||
createLocation: jest.fn(), | ||
isActive: jest.fn(), | ||
matcher: { | ||
match: jest.fn(), | ||
getRoutes: jest.fn(), | ||
isActive: jest.fn(), | ||
format: jest.fn(), | ||
}, | ||
addTransitionHook: jest.fn(), | ||
}; | ||
|
||
describe('<RouterProvider>', () => { | ||
it('should render children', () => { | ||
let wrapper; | ||
|
||
wrapper = mount( | ||
<RouterProvider router={router}> | ||
<div /> | ||
</RouterProvider> | ||
); | ||
expect(wrapper.find('div')).toHaveLength(1); | ||
|
||
const CustomCompoment = () => <div />; | ||
wrapper = mount( | ||
<RouterProvider router={router}> | ||
<CustomCompoment /> | ||
</RouterProvider> | ||
); | ||
expect(wrapper.find(CustomCompoment)).toHaveLength(1); | ||
}); | ||
|
||
it('should pass router to children cotext', () => { | ||
let routerInContext; | ||
const Child = class extends React.Component { // eslint-disable-line react/prefer-stateless-function | ||
static contextTypes = { | ||
router: routerShape.isRequired, | ||
}; | ||
|
||
render() { | ||
routerInContext = this.context.router; | ||
return <div />; | ||
} | ||
}; | ||
|
||
mount( | ||
<RouterProvider router={router}> | ||
<Child /> | ||
</RouterProvider> | ||
); | ||
expect(routerInContext).toBeDefined(); | ||
}); | ||
}); |