Skip to content

Commit 77ba566

Browse files
committed
More tests, finished porting
1 parent 84630df commit 77ba566

File tree

7 files changed

+69
-225
lines changed

7 files changed

+69
-225
lines changed

modules/components/__tests__/DefaultRoute-test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ var PathStore = require('../../stores/PathStore');
88
var Route = require('../Route');
99
var DefaultRoute = require('../DefaultRoute');
1010

11+
afterEach(function () {
12+
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
13+
PathStore.removeAllChangeListeners();
14+
});
15+
1116
describe('A DefaultRoute', function () {
1217
it('has a null path', function () {
1318
expect(DefaultRoute({ path: '/' }).props.path).toBe(null);
@@ -85,8 +90,6 @@ describe('when no child routes match a URL, but the parent\'s path matches', fun
8590

8691
afterEach(function () {
8792
React.unmountComponentAtNode(component.getDOMNode());
88-
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
89-
PathStore.removeAllChangeListeners();
9093
});
9194

9295
it('matches the default route', function () {

modules/components/__tests__/NotFoundRoute-test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ var PathStore = require('../../stores/PathStore');
88
var Route = require('../Route');
99
var NotFoundRoute = require('../NotFoundRoute');
1010

11+
afterEach(function () {
12+
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
13+
PathStore.removeAllChangeListeners();
14+
});
15+
1116
describe('A NotFoundRoute', function () {
1217
it('has a null path', function () {
1318
expect(NotFoundRoute({ path: '/' }).props.path).toBe(null);
@@ -85,8 +90,6 @@ describe('when no child routes match a URL, but the beginning of the parent\'s p
8590

8691
afterEach(function () {
8792
React.unmountComponentAtNode(component.getDOMNode());
88-
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
89-
PathStore.removeAllChangeListeners();
9093
});
9194

9295
it('matches the NotFoundRoute', function () {

modules/components/__tests__/Routes-test.js

+59-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function getRootMatch(matches) {
1010
return matches[matches.length - 1];
1111
}
1212

13+
afterEach(function () {
14+
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
15+
PathStore.removeAllChangeListeners();
16+
});
17+
1318
describe('A Routes', function () {
1419

1520
var App = React.createClass({
@@ -32,8 +37,6 @@ describe('A Routes', function () {
3237

3338
afterEach(function () {
3439
React.unmountComponentAtNode(component.getDOMNode());
35-
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
36-
PathStore.removeAllChangeListeners();
3740
});
3841

3942
it('returns an array', function () {
@@ -60,8 +63,6 @@ describe('A Routes', function () {
6063

6164
afterEach(function () {
6265
React.unmountComponentAtNode(component.getDOMNode());
63-
// For some reason unmountComponentAtNode doesn't call componentWillUnmount :/
64-
PathStore.removeAllChangeListeners();
6566
});
6667

6768
it('returns an array with the correct params', function () {
@@ -74,4 +75,58 @@ describe('A Routes', function () {
7475
});
7576
});
7677

78+
79+
describe('when a transition is aborted', function () {
80+
it('triggers onAbortedTransition', function (done) {
81+
var App = React.createClass({
82+
statics: {
83+
willTransitionTo: function (transition) {
84+
transition.abort();
85+
}
86+
},
87+
render: function () {
88+
return React.DOM.div();
89+
}
90+
});
91+
92+
function handleAbortedTransition(transition) {
93+
assert(transition);
94+
done();
95+
}
96+
97+
ReactTestUtils.renderIntoDocument(
98+
Routes({ onAbortedTransition: handleAbortedTransition },
99+
Route({ handler: App })
100+
)
101+
);
102+
});
103+
});
104+
105+
describe('when there is an error in a transition hook', function () {
106+
it('triggers onTransitionError', function (done) {
107+
var App = React.createClass({
108+
statics: {
109+
willTransitionTo: function (transition) {
110+
throw new Error('boom!');
111+
}
112+
},
113+
render: function () {
114+
return React.DOM.div();
115+
}
116+
});
117+
118+
function handleTransitionError(error) {
119+
assert(error);
120+
expect(error.message).toEqual('boom!');
121+
done();
122+
}
123+
124+
ReactTestUtils.renderIntoDocument(
125+
Routes({ onTransitionError: handleTransitionError },
126+
Route({ handler: App })
127+
)
128+
);
129+
});
130+
});
131+
77132
});

specs/Route.spec.js

-118
This file was deleted.

specs/Routes.spec.js

-60
This file was deleted.

specs/helper.js

-30
This file was deleted.

specs/main.js

-9
This file was deleted.

0 commit comments

Comments
 (0)