Skip to content

Commit e5c18c9

Browse files
taiontimdorr
authored andcommitted
Update helpers for warning messages (#3638)
This doesn't change any behavior. It just syncs up the logic to the latest that I have elsewhere.
1 parent cb43c7d commit e5c18c9

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

modules/__tests__/shouldWarn.js

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

tests.webpack.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
/* eslint-env mocha */
2-
/* eslint-disable no-console */
32

43
import expect from 'expect'
54

65
import { _resetWarned } from './modules/routerWarning'
76

87
beforeEach(() => {
8+
/* eslint-disable no-console */
99
expect.spyOn(console, 'error').andCall(msg => {
10-
for (const about of console.error.expected) {
10+
let expected = false
11+
12+
console.error.expected.forEach(about => {
1113
if (msg.indexOf(about) !== -1) {
1214
console.error.warned[about] = true
13-
return
15+
expected = true
1416
}
15-
}
17+
})
18+
19+
if (expected)
20+
return
1621

1722
console.error.threw = true
1823
throw new Error(msg)
@@ -21,18 +26,21 @@ beforeEach(() => {
2126
console.error.expected = []
2227
console.error.warned = Object.create(null)
2328
console.error.threw = false
29+
/* eslint-enable no-console */
2430
})
2531

2632
afterEach(() => {
27-
if (!console.error.threw) {
28-
console.error.expected.forEach(about => {
29-
expect(console.error.warned[about]).toExist(
30-
`Missing expected warning: ${about}`
31-
)
33+
/* eslint-disable no-console */
34+
const { threw, expected, warned } = console.error
35+
console.error.restore()
36+
37+
if (!threw) {
38+
expected.forEach(about => {
39+
expect(warned[about]).toExist(`Missing expected warning: ${about}`)
3240
})
3341
}
42+
/* eslint-enable no-console */
3443

35-
console.error.restore()
3644
_resetWarned()
3745
})
3846

0 commit comments

Comments
 (0)