1
1
/* eslint-env mocha */
2
- /* eslint-disable no-console */
3
2
4
3
import expect from 'expect'
5
4
6
5
import { _resetWarned } from './modules/routerWarning'
7
6
8
7
beforeEach ( ( ) => {
8
+ /* eslint-disable no-console */
9
9
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 => {
11
13
if ( msg . indexOf ( about ) !== - 1 ) {
12
14
console . error . warned [ about ] = true
13
- return
15
+ expected = true
14
16
}
15
- }
17
+ } )
18
+
19
+ if ( expected )
20
+ return
16
21
17
22
console . error . threw = true
18
23
throw new Error ( msg )
@@ -21,18 +26,21 @@ beforeEach(() => {
21
26
console . error . expected = [ ]
22
27
console . error . warned = Object . create ( null )
23
28
console . error . threw = false
29
+ /* eslint-enable no-console */
24
30
} )
25
31
26
32
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 } ` )
32
40
} )
33
41
}
42
+ /* eslint-enable no-console */
34
43
35
- console . error . restore ( )
36
44
_resetWarned ( )
37
45
} )
38
46
0 commit comments