Skip to content

Commit 7bd7f89

Browse files
committed
Fix some tests
1 parent b8c69a0 commit 7bd7f89

File tree

6 files changed

+48
-50
lines changed

6 files changed

+48
-50
lines changed

modules/__tests__/Link-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Link from '../Link';
99

1010
var { click } = React.addons.TestUtils.Simulate;
1111

12-
describe.skip('A <Link>', function () {
12+
describe('A <Link>', function () {
1313

1414
var Parent = React.createClass({
1515
render() {
@@ -133,7 +133,7 @@ describe.skip('A <Link>', function () {
133133
function () {
134134
a = node.querySelector('a');
135135
expect(a.className).toEqual('dontKillMe');
136-
this.transitionTo('/hello');
136+
this.history.pushState(null, '/hello');
137137
},
138138
function () {
139139
expect(a.className).toEqual('dontKillMe');
@@ -170,7 +170,7 @@ describe.skip('A <Link>', function () {
170170
function () {
171171
a = node.querySelector('a');
172172
expect(a.className).toEqual('dontKillMe');
173-
this.transitionTo('/hello');
173+
this.history.pushState(null, '/hello');
174174
},
175175
function () {
176176
expect(a.className).toEqual('dontKillMe highlight');
@@ -205,7 +205,7 @@ describe.skip('A <Link>', function () {
205205
function () {
206206
a = node.querySelector('a');
207207
expect(a.style.color).toEqual('white');
208-
this.transitionTo('/hello');
208+
this.history.pushState(null, '/hello');
209209
},
210210
function () {
211211
expect(a.style.color).toEqual('red');

modules/__tests__/Redirect-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Redirect from '../Redirect';
55
import Router from '../Router';
66
import Route from '../Route';
77

8-
describe.skip('A <Redirect>', function () {
8+
describe('A <Redirect>', function () {
99
var node;
1010
beforeEach(function () {
1111
node = document.createElement('div');

modules/__tests__/Router-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import expect from 'expect';
22
import React from 'react';
3-
import { createLocation } from 'history';
3+
import createHistory from 'history/lib/createMemoryHistory';
44
import Router from '../Router';
55
import Route from '../Route';
66

7-
describe.skip('Router', function () {
7+
describe('Router', function () {
88

99
var node;
1010
beforeEach(function () {
@@ -29,7 +29,7 @@ describe.skip('Router', function () {
2929

3030
it('renders routes', function (done) {
3131
React.render((
32-
<Router location={createLocation('/')}>
32+
<Router history={createHistory('/')}>
3333
<Route path="/" component={Parent} />
3434
</Router>
3535
), node, function () {
@@ -40,7 +40,7 @@ describe.skip('Router', function () {
4040

4141
it('renders child routes when the parent does not have a path', function (done) {
4242
React.render((
43-
<Router location={createLocation('/')}>
43+
<Router history={createHistory('/')}>
4444
<Route component={Parent}>
4545
<Route component={Parent}>
4646
<Route path="/" component={Child} />
@@ -55,7 +55,7 @@ describe.skip('Router', function () {
5555

5656
it('renders nested children correctly', function (done) {
5757
React.render((
58-
<Router location={createLocation('/hello')}>
58+
<Router history={createHistory('/hello')}>
5959
<Route component={Parent}>
6060
<Route path="hello" component={Child} />
6161
</Route>
@@ -69,7 +69,7 @@ describe.skip('Router', function () {
6969

7070
it('renders the child\'s component when it has no component', function (done) {
7171
React.render((
72-
<Router location={createLocation('/hello')}>
72+
<Router history={createHistory('/hello')}>
7373
<Route>
7474
<Route path="hello" component={Child} />
7575
</Route>
@@ -95,7 +95,7 @@ describe.skip('Router', function () {
9595
});
9696

9797
React.render((
98-
<Router location={createLocation('/')} createElement={Component => <Wrapper Component={Component} />}>
98+
<Router history={createHistory('/')} createElement={Component => <Wrapper Component={Component} />}>
9999
<Route path="/" component={Component}/>
100100
</Router>
101101
), node, function () {

modules/__tests__/ActiveMixin-test.js renamed to modules/__tests__/isActive-test.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import expect from 'expect';
22
import React from 'react';
3-
import createLocation from 'history/lib/createLocation';
43
import createHistory from 'history/lib/createMemoryHistory';
54
import Router from '../Router';
65
import Route from '../Route';
76

8-
describe.skip('ActiveMixin', function () {
7+
describe('isActive', function () {
98

109
var node;
1110
beforeEach(function () {
@@ -20,11 +19,11 @@ describe.skip('ActiveMixin', function () {
2019
describe('with no query', function () {
2120
it('is active', function (done) {
2221
React.render((
23-
<Router location={createLocation('/home')}>
22+
<Router history={createHistory('/home')}>
2423
<Route path="/home" />
2524
</Router>
2625
), node, function () {
27-
expect(this.isActive('/home')).toBe(true);
26+
expect(this.history.isActive('/home')).toBe(true);
2827
done();
2928
});
3029
});
@@ -33,11 +32,11 @@ describe.skip('ActiveMixin', function () {
3332
describe('with a query that also matches', function () {
3433
it('is active', function (done) {
3534
React.render((
36-
<Router location={createLocation('/home?the=query')}>
35+
<Router history={createHistory('/home?the=query')}>
3736
<Route path="/home" />
3837
</Router>
3938
), node, function () {
40-
expect(this.isActive('/home', { the: 'query' })).toBe(true);
39+
expect(this.history.isActive('/home', { the: 'query' })).toBe(true);
4140
done();
4241
});
4342
});
@@ -46,11 +45,11 @@ describe.skip('ActiveMixin', function () {
4645
describe('with a query that does not match', function () {
4746
it('is not active', function (done) {
4847
React.render((
49-
<Router location={createLocation('/home?the=query')}>
48+
<Router history={createHistory('/home?the=query')}>
5049
<Route path="/home" />
5150
</Router>
5251
), node, function () {
53-
expect(this.isActive('/home', { something: 'else' })).toBe(false);
52+
expect(this.history.isActive('/home', { something: 'else' })).toBe(false);
5453
done();
5554
});
5655
});
@@ -61,13 +60,13 @@ describe.skip('ActiveMixin', function () {
6160
describe('with no query', function () {
6261
it('is active', function (done) {
6362
React.render((
64-
<Router location={createLocation('/absolute')}>
63+
<Router history={createHistory('/absolute')}>
6564
<Route path="/home">
6665
<Route path="/absolute" />
6766
</Route>
6867
</Router>
6968
), node, function () {
70-
expect(this.isActive('/home')).toBe(true);
69+
expect(this.history.isActive('/home')).toBe(true);
7170
done();
7271
});
7372
});
@@ -76,13 +75,13 @@ describe.skip('ActiveMixin', function () {
7675
describe('with a query that also matches', function () {
7776
it('is active', function (done) {
7877
React.render((
79-
<Router location={createLocation('/absolute?the=query')}>
78+
<Router history={createHistory('/absolute?the=query')}>
8079
<Route path="/home">
8180
<Route path="/absolute" />
8281
</Route>
8382
</Router>
8483
), node, function () {
85-
expect(this.isActive('/home', { the: 'query' })).toBe(true);
84+
expect(this.history.isActive('/home', { the: 'query' })).toBe(true);
8685
done();
8786
});
8887
});
@@ -91,13 +90,13 @@ describe.skip('ActiveMixin', function () {
9190
describe('with a query that does not match', function () {
9291
it('is active', function (done) {
9392
React.render((
94-
<Router location={createLocation('/absolute?the=query')}>
93+
<Router history={createHistory('/absolute?the=query')}>
9594
<Route path="/home">
9695
<Route path="/absolute" />
9796
</Route>
9897
</Router>
9998
), node, function () {
100-
expect(this.isActive('/home', { something: 'else' })).toBe(false);
99+
expect(this.history.isActive('/home', { something: 'else' })).toBe(false);
101100
done();
102101
});
103102
});
@@ -107,11 +106,11 @@ describe.skip('ActiveMixin', function () {
107106
describe('a pathname that matches only the beginning of the URL', function () {
108107
it('is not active', function (done) {
109108
React.render((
110-
<Router location={createLocation('/home')}>
109+
<Router history={createHistory('/home')}>
111110
<Route path="/home" />
112111
</Router>
113112
), node, function () {
114-
expect(this.isActive('/h')).toBe(false);
113+
expect(this.history.isActive('/h')).toBe(false);
115114
done();
116115
});
117116
});

modules/__tests__/transitionTo-test.js renamed to modules/__tests__/pushState-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import execSteps from './execSteps';
66
import Router from '../Router';
77
import Route from '../Route';
88

9-
describe('transitionTo', function () {
9+
describe('pushState', function () {
1010
beforeEach(resetHash);
1111

1212
var node;
@@ -18,7 +18,7 @@ describe('transitionTo', function () {
1818
React.unmountComponentAtNode(node);
1919
});
2020

21-
describe.skip('when the target path contains a colon', function () {
21+
describe('when the target path contains a colon', function () {
2222
it('works', function (done) {
2323
var Index = React.createClass({
2424
render() {
@@ -35,7 +35,7 @@ describe('transitionTo', function () {
3535
var steps = [
3636
function () {
3737
expect(this.state.location.pathname).toEqual('/');
38-
this.transitionTo('/home/hi:there');
38+
this.history.pushState(null, '/home/hi:there');
3939
},
4040
function () {
4141
expect(this.state.location.pathname).toEqual('/home/hi:there');

modules/__tests__/transitionHooks-test.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import execSteps from './execSteps';
55
import Router from '../Router';
66
import Route from '../Route';
77

8-
describe.skip('When a router enters a branch', function () {
8+
describe('When a router enters a branch', function () {
99
var node, Dashboard, NewsFeed, Inbox, DashboardRoute, NewsFeedRoute, InboxRoute, RedirectToInboxRoute, MessageRoute, routes;
1010
beforeEach(function () {
1111
node = document.createElement('div');
@@ -37,64 +37,63 @@ describe.skip('When a router enters a branch', function () {
3737
path: 'news',
3838
component: NewsFeed,
3939
onEnter(nextState, redirectTo) {
40+
expect(this).toBe(NewsFeedRoute);
4041
expect(nextState.routes).toContain(NewsFeedRoute);
4142
expect(redirectTo).toBeA('function');
4243
},
43-
onLeave(nextState, redirectTo) {
44-
expect(nextState.routes).toNotContain(NewsFeedRoute);
45-
expect(redirectTo).toBeA('function');
44+
onLeave() {
45+
expect(this).toBe(NewsFeedRoute);
4646
}
4747
};
4848

4949
InboxRoute = {
5050
path: 'inbox',
5151
component: Inbox,
5252
onEnter(nextState, redirectTo) {
53+
expect(this).toBe(InboxRoute);
5354
expect(nextState.routes).toContain(InboxRoute);
5455
expect(redirectTo).toBeA('function');
5556
},
56-
onLeave(nextState, redirectTo) {
57-
expect(nextState.routes).toNotContain(InboxRoute);
58-
expect(redirectTo).toBeA('function');
57+
onLeave() {
58+
expect(this).toBe(InboxRoute);
5959
}
6060
};
6161

6262
RedirectToInboxRoute = {
6363
path: 'redirect-to-inbox',
6464
onEnter(nextState, redirectTo) {
65+
expect(this).toBe(RedirectToInboxRoute);
6566
expect(nextState.routes).toContain(RedirectToInboxRoute);
6667
expect(redirectTo).toBeA('function');
6768

6869
redirectTo('/inbox');
6970
},
70-
onLeave(nextState, redirectTo) {
71-
expect(nextState.routes).toNotContain(RedirectToInboxRoute);
72-
expect(redirectTo).toBeA('function');
71+
onLeave() {
72+
expect(this).toBe(RedirectToInboxRoute);
7373
}
7474
};
7575

7676
MessageRoute = {
7777
path: 'messages/:messageID',
7878
onEnter(nextState, redirectTo) {
79+
expect(this).toBe(MessageRoute);
7980
expect(nextState.routes).toContain(MessageRoute);
8081
expect(redirectTo).toBeA('function');
8182
},
82-
onLeave(nextState, redirectTo) {
83-
// We can't make this assertion when switching from /messages/123 => /messages/456
84-
//expect(nextState.routes).toNotContain(MessageRoute);
85-
expect(redirectTo).toBeA('function');
83+
onLeave() {
84+
expect(this).toBe(MessageRoute);
8685
}
8786
};
8887

8988
DashboardRoute = {
9089
component: Dashboard,
9190
onEnter(nextState, redirectTo) {
91+
expect(this).toBe(DashboardRoute);
9292
expect(nextState.routes).toContain(DashboardRoute);
9393
expect(redirectTo).toBeA('function');
9494
},
95-
onLeave(nextState, redirectTo) {
96-
expect(nextState.routes).toNotContain(DashboardRoute);
97-
expect(redirectTo).toBeA('function');
95+
onLeave() {
96+
expect(this).toBe(DashboardRoute);
9897
},
9998
childRoutes: [ NewsFeedRoute, InboxRoute, RedirectToInboxRoute, MessageRoute ]
10099
};
@@ -144,7 +143,7 @@ describe.skip('When a router enters a branch', function () {
144143
var steps = [
145144
function () {
146145
expect(inboxRouteEnterSpy).toHaveBeenCalled('InboxRoute.onEnter was not called');
147-
this.transitionTo('/news');
146+
this.history.pushState(null, '/news');
148147
},
149148
function () {
150149
expect(inboxRouteLeaveSpy).toHaveBeenCalled('InboxRoute.onLeave was not called');
@@ -173,7 +172,7 @@ describe.skip('When a router enters a branch', function () {
173172
function () {
174173
expect(dashboardRouteEnterSpy).toHaveBeenCalled('DashboardRoute.onEnter was not called');
175174
expect(messageRouteEnterSpy).toHaveBeenCalled('InboxRoute.onEnter was not called');
176-
this.transitionTo('/messages/456');
175+
this.history.pushState(null, '/messages/456');
177176
},
178177
function () {
179178
expect(messageRouteLeaveSpy).toHaveBeenCalled('MessageRoute.onLeave was not called');

0 commit comments

Comments
 (0)