Skip to content

Commit 59d6727

Browse files
committed
chore(tests): add tests for UIRouterConsumer
1 parent 58189ec commit 59d6727

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

src/components/UIRouter.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ export class UIRouter extends Component<UIRouterProps, UIRouterState> {
9494
}
9595

9696
render() {
97-
return (
98-
<UIRouterProvider value={this.router}>
99-
{this.props.children}
100-
</UIRouterProvider>
101-
);
97+
return <UIRouterProvider value={this.router}>{this.props.children}</UIRouterProvider>;
10298
}
10399
}

src/components/__tests__/UIRouter.test.tsx

+34-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import * as React from 'react';
44
import * as PropTypes from 'prop-types';
55
import { mount } from 'enzyme';
66

7-
import {
8-
UIRouter,
9-
UIRouterConsumer,
10-
UIRouterReact,
11-
memoryLocationPlugin,
12-
} from '../../index';
7+
import { UIRouter, UIRouterConsumer, UIRouterReact, memoryLocationPlugin } from '../../index';
138

149
class Child extends React.Component<any, any> {
1510
static propTypes: React.ValidationMap<any> = {
@@ -34,9 +29,7 @@ describe('<UIRouter>', () => {
3429
it('creates a router instance', () => {
3530
const wrapper = mount(
3631
<UIRouter plugins={[memoryLocationPlugin]} states={[]}>
37-
<UIRouterConsumer>
38-
{router => <Child router={router} />}
39-
</UIRouterConsumer>
32+
<UIRouterConsumer>{router => <Child router={router} />}</UIRouterConsumer>
4033
</UIRouter>,
4134
);
4235
expect(wrapper.find(Child).props().router).toBeDefined();
@@ -45,14 +38,41 @@ describe('<UIRouter>', () => {
4538
it('accepts an instance via prop', () => {
4639
const router = new UIRouterReact();
4740
router.plugin(memoryLocationPlugin);
48-
(router as any).__TEST__ = true;
4941
const wrapper = mount(
5042
<UIRouter router={router}>
51-
<UIRouterConsumer>
52-
{router => <Child router={router} />}
53-
</UIRouterConsumer>
43+
<UIRouterConsumer>{router => <Child router={router} />}</UIRouterConsumer>
5444
</UIRouter>,
5545
);
56-
expect(wrapper.find(Child).props().router.__TEST__).toBe(true);
46+
expect(wrapper.find(Child).props().router).toBe(router);
47+
});
48+
49+
describe('<UIRouterCosumer>', () => {
50+
it('passes down the router instance', () => {
51+
const wrapper = mount(
52+
<UIRouter plugins={[memoryLocationPlugin]}>
53+
<UIRouterConsumer>
54+
{router => {
55+
expect(router).toBeInstanceOf(UIRouterReact);
56+
return null;
57+
}}
58+
</UIRouterConsumer>
59+
</UIRouter>,
60+
);
61+
});
62+
63+
it('passes down the correct router instance when passed via props', () => {
64+
const router = new UIRouterReact();
65+
router.plugin(memoryLocationPlugin);
66+
const wrapper = mount(
67+
<UIRouter router={router}>
68+
<UIRouterConsumer>
69+
{_router => {
70+
expect(_router).toBe(router);
71+
return null;
72+
}}
73+
</UIRouterConsumer>
74+
</UIRouter>,
75+
);
76+
});
5777
});
5878
});

0 commit comments

Comments
 (0)