@@ -6,10 +6,11 @@ const consoleOutput = require('../output/console');
6
6
7
7
describe ( 'Logger' , function ( ) {
8
8
let logger ;
9
+ let outputStub ;
9
10
10
11
beforeEach ( function ( ) {
11
12
logger = new Logger ( 'mongo' , true ) ;
12
- this . sandbox . stub ( console , 'log ' ) ;
13
+ outputStub = this . sandbox . stub ( Logger . config , 'output ' ) ;
13
14
} ) ;
14
15
15
16
afterEach ( function ( ) {
@@ -23,7 +24,7 @@ describe('Logger', function() {
23
24
it ( 'should call log info method when enabled' , function ( ) {
24
25
logger . info ( 'wedidit' , { details : 'forever' } ) ;
25
26
26
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
27
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
27
28
expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
28
29
expect ( logArguments . action ) . to . eql ( 'wedidit' ) ;
29
30
expect ( logArguments . level ) . to . eql ( 30 ) ;
@@ -35,7 +36,7 @@ describe('Logger', function() {
35
36
36
37
logger . info ( 'hi' ) ;
37
38
38
- expect ( console . log ) . not . to . have . been . called ;
39
+ expect ( Logger . config . output ) . not . to . have . been . called ;
39
40
} ) ;
40
41
41
42
it ( 'should not call log info method when disabled' , function ( ) {
@@ -55,7 +56,7 @@ describe('Logger', function() {
55
56
56
57
logger . fromError ( 'hi' , error , { details : 'here' } ) ;
57
58
58
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
59
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
59
60
expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
60
61
expect ( logArguments . action ) . to . eql ( 'hi' ) ;
61
62
expect ( logArguments . level ) . to . eql ( 50 ) ;
@@ -73,7 +74,7 @@ describe('Logger', function() {
73
74
74
75
logger . warnFromError ( 'hi' , error , { details : 'here' } ) ;
75
76
76
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
77
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
77
78
expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
78
79
expect ( logArguments . action ) . to . eql ( 'hi' ) ;
79
80
expect ( logArguments . level ) . to . eql ( 40 ) ;
@@ -90,7 +91,7 @@ describe('Logger', function() {
90
91
91
92
logger . warnFromError ( 'hi' , error , { details : 'here' } ) ;
92
93
93
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
94
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
94
95
expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
95
96
expect ( logArguments . action ) . to . eql ( 'hi' ) ;
96
97
expect ( logArguments . level ) . to . eql ( 40 ) ;
@@ -108,7 +109,7 @@ describe('Logger', function() {
108
109
109
110
logger . warnFromError ( 'hi' , error , { details : 'here' } ) ;
110
111
111
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
112
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
112
113
expect ( logArguments . name ) . to . eql ( 'mongo' ) ;
113
114
expect ( logArguments . action ) . to . eql ( 'hi' ) ;
114
115
expect ( logArguments . level ) . to . eql ( 40 ) ;
@@ -132,7 +133,7 @@ describe('Logger', function() {
132
133
logger . info ( 'hi' ) ;
133
134
134
135
expect ( formatterStub ) . to . have . been . called ;
135
- expect ( console . log ) . to . have . been . calledWith ( formattedOutput ) ;
136
+ expect ( Logger . config . output ) . to . have . been . calledWith ( formattedOutput ) ;
136
137
} ) ;
137
138
138
139
it ( 'should change output method' , function ( ) {
@@ -151,7 +152,7 @@ describe('Logger', function() {
151
152
invalid : true
152
153
} ) ;
153
154
throw new Error ( 'should throw' ) ;
154
- } catch ( e ) {
155
+ } catch ( e ) {
155
156
expect ( e . message ) . to . eql ( 'Only the following keys are allowed: formatter, output' ) ;
156
157
}
157
158
} ) ;
@@ -165,7 +166,7 @@ describe('Logger', function() {
165
166
166
167
logger . info ( 'hi' ) ;
167
168
168
- const logArguments = JSON . parse ( console . log . args [ 0 ] ) ;
169
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
169
170
expect ( logArguments . action ) . to . eql ( 'hi' ) ;
170
171
expect ( logArguments . debug ) . to . eql ( true ) ;
171
172
} ) ;
0 commit comments