Skip to content

Commit 2e862ec

Browse files
committed
Assert on specific warnings in tests
1 parent fcd09f2 commit 2e862ec

12 files changed

+81
-73
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ sudo: false
22
language: node_js
33
node_js:
44
- stable
5-
env:
6-
-
7-
- SKIP_BC=1 FAIL_ON_WARNINGS=1
85
cache:
96
directories:
107
- node_modules

karma.conf.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ module.exports = function (config) {
106106
},
107107
plugins: [
108108
new webpack.DefinePlugin({
109-
'process.env.NODE_ENV': JSON.stringify('test'),
110-
'process.env.SKIP_BC': JSON.stringify(process.env.SKIP_BC || false),
111-
'process.env.FAIL_ON_WARNINGS': JSON.stringify(process.env.FAIL_ON_WARNINGS || false)
109+
'process.env.NODE_ENV': JSON.stringify('test')
112110
})
113111
]
114112
},
@@ -157,19 +155,3 @@ module.exports = function (config) {
157155
}
158156
}
159157
}
160-
161-
console.log()
162-
console.log('===')
163-
if (process.env.SKIP_BC) {
164-
console.warn('`SKIP_BC=1` detected: skipping backwards compatibility tests')
165-
} else {
166-
console.log('`SKIP_BC=1 npm run *` to skip backwards compatibility tests.')
167-
}
168-
169-
if (process.env.FAIL_ON_WARNINGS) {
170-
console.warn('`FAIL_ON_WARNINGS=1` detected: console.error will now fail tests.')
171-
} else {
172-
console.log('`FAIL_ON_WARNINGS=1 npm run *` to cause console warnings to throw errors.')
173-
}
174-
console.log('===')
175-
console.log()

modules/__tests__/_bc-History-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import History from '../History'
55
import Router from '../Router'
66
import Route from '../Route'
77
import createHistory from 'history/lib/createMemoryHistory'
8+
import shouldWarn from './shouldWarn'
89

9-
// skipping to remove warnings, and we don't intent to update this mixin
10-
// keeping tests here just in-case
1110
describe('v1 History Mixin', function () {
1211

1312
let node
@@ -19,7 +18,12 @@ describe('v1 History Mixin', function () {
1918
unmountComponentAtNode(node)
2019
})
2120

21+
beforeEach(function () {
22+
shouldWarn('deprecated')
23+
})
24+
2225
it('assigns the history to the component instance', function (done) {
26+
2327
const history = createHistory('/')
2428

2529
const Component = React.createClass({

modules/__tests__/_bc-Link-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import createHistory from 'history/lib/createMemoryHistory'
77
import Router from '../Router'
88
import Route from '../Route'
99
import Link from '../Link'
10+
import shouldWarn from './shouldWarn'
1011

1112
const { click } = Simulate
1213

@@ -23,6 +24,10 @@ describe('v1 Link', function () {
2324
node = document.createElement('div')
2425
})
2526

27+
beforeEach(function () {
28+
shouldWarn('deprecated')
29+
})
30+
2631
it('knows how to make its href', function () {
2732
class LinkWrapper extends Component {
2833
render() {

modules/__tests__/_bc-Router-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { render, unmountComponentAtNode } from 'react-dom'
44
import createHistory from 'history/lib/createMemoryHistory'
55
import Route from '../Route'
66
import Router from '../Router'
7+
import shouldWarn from './shouldWarn'
78

89
describe('v1 Router', function () {
9-
1010
class Parent extends Component {
1111
render() {
1212
return <div>parent {this.props.children}</div>
@@ -28,6 +28,10 @@ describe('v1 Router', function () {
2828
unmountComponentAtNode(node)
2929
})
3030

31+
beforeEach(function () {
32+
shouldWarn('deprecated')
33+
})
34+
3135
it('renders routes', function (done) {
3236
render((
3337
<Router history={createHistory('/')}>

modules/__tests__/_bc-isActive-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import IndexRoute from '../IndexRoute'
66
import Router from '../Router'
77
import Route from '../Route'
88
import qs from 'qs'
9+
import shouldWarn from './shouldWarn'
910

1011
describe('v1 isActive', function () {
1112

@@ -18,6 +19,10 @@ describe('v1 isActive', function () {
1819
unmountComponentAtNode(node)
1920
})
2021

22+
beforeEach(function () {
23+
shouldWarn('deprecated')
24+
})
25+
2126
describe('a pathname that matches the URL', function () {
2227
describe('with no query', function () {
2328
it('is active', function (done) {

modules/__tests__/_bc-serverRendering-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { renderToString } from 'react-dom/server'
55
import Link from '../Link'
66
import match from '../match'
77
import RoutingContext from '../RoutingContext'
8+
import shouldWarn from './shouldWarn'
89

910
describe('v1 server rendering', function () {
1011

@@ -67,6 +68,8 @@ describe('v1 server rendering', function () {
6768
}
6869

6970
it('works', function (done) {
71+
shouldWarn('has been renamed')
72+
7073
match({ routes, location: '/dashboard' }, function (error, redirectLocation, renderProps) {
7174
const string = renderToString(
7275
<RoutingContext {...renderProps} />
@@ -77,6 +80,8 @@ describe('v1 server rendering', function () {
7780
})
7881

7982
it('renders active Links as active', function (done) {
83+
shouldWarn('has been renamed')
84+
8085
match({ routes, location: '/about' }, function (error, redirectLocation, renderProps) {
8186
const string = renderToString(
8287
<RoutingContext {...renderProps} />
@@ -88,6 +93,8 @@ describe('v1 server rendering', function () {
8893
})
8994

9095
it('sends the redirect location', function (done) {
96+
shouldWarn('deprecated')
97+
9198
match({ routes, location: '/company' }, function (error, redirectLocation) {
9299
expect(redirectLocation).toExist()
93100
expect(redirectLocation.pathname).toEqual('/about')

modules/__tests__/_bc-transitionHooks-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import expect, { spyOn } from 'expect'
22
import React, { Component } from 'react'
33
import { render, unmountComponentAtNode } from 'react-dom'
44
import createHistory from 'history/lib/createMemoryHistory'
5-
import useQueries from 'history/lib/useQueries'
65
import execSteps from './execSteps'
76
import Router from '../Router'
7+
import shouldWarn from './shouldWarn'
88

99
describe('v1 When a router enters a branch', function () {
1010

@@ -109,6 +109,10 @@ describe('v1 When a router enters a branch', function () {
109109
unmountComponentAtNode(node)
110110
})
111111

112+
beforeEach(function () {
113+
shouldWarn('deprecated')
114+
})
115+
112116
it('calls the onEnter hooks of all routes in that branch', function (done) {
113117
const dashboardRouteEnterSpy = spyOn(DashboardRoute, 'onEnter').andCallThrough()
114118
const newsFeedRouteEnterSpy = spyOn(NewsFeedRoute, 'onEnter').andCallThrough()
@@ -196,7 +200,7 @@ describe('v1 When a router enters a branch', function () {
196200
describe('and then the query changes', function () {
197201
it('calls the onEnter hooks of all routes in that branch', function (done) {
198202
const newsFeedRouteEnterSpy = spyOn(NewsFeedRoute, 'onEnter').andCallThrough()
199-
const history = useQueries(createHistory)('/inbox')
203+
const history = createHistory('/inbox')
200204

201205
render(<Router history={history} routes={routes}/>, node, function () {
202206
history.pushState(null, '/news', { q: 1 })

modules/__tests__/matchRoutes-test.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createRoutes } from '../RouteUtils'
55
import matchRoutes from '../matchRoutes'
66
import Route from '../Route'
77
import IndexRoute from '../IndexRoute'
8+
import shouldWarn from './shouldWarn'
89

910
describe('matchRoutes', function () {
1011
let routes
@@ -331,33 +332,18 @@ describe('matchRoutes', function () {
331332
})
332333
})
333334

334-
describe('invalid route configs', function () {
335-
let invalidRoutes, errorSpy
335+
it('complains about invalid index route with path', function (done) {
336+
shouldWarn('path')
336337

337-
beforeEach(function () {
338-
errorSpy = expect.spyOn(console, 'error')
339-
})
340-
341-
afterEach(function () {
342-
errorSpy.restore()
343-
})
344-
345-
describe('index route with path', function () {
346-
beforeEach(function () {
347-
invalidRoutes = createRoutes(
348-
<Route path="/">
349-
<IndexRoute path="foo" />
350-
</Route>
351-
)
352-
})
338+
const invalidRoutes = createRoutes(
339+
<Route path="/">
340+
<IndexRoute path="foo" />
341+
</Route>
342+
)
353343

354-
it('complains when matching', function (done) {
355-
matchRoutes(invalidRoutes, createLocation('/'), function (error, match) {
356-
expect(match).toExist()
357-
expect(errorSpy).toHaveBeenCalledWith('Warning: [react-router] Index routes should not have paths')
358-
done()
359-
})
360-
})
344+
matchRoutes(invalidRoutes, createLocation('/'), function (error, match) {
345+
expect(match).toExist()
346+
done()
361347
})
362348
})
363349
})

modules/__tests__/shouldWarn.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*eslint no-console: 0*/
2+
3+
export default function shouldWarn(about) {
4+
console.error.expected.push(about)
5+
}

0 commit comments

Comments
 (0)