@@ -71,21 +71,35 @@ describe('Logger', () => {
7171
7272 describe ( 'msg field validation' , ( ) => {
7373 it ( 'should throw when object is missing msg field' , ( ) => {
74+ const stream = new TestStream ( ) ;
75+ const consumer = new JSONConsumer ( { stream, level : 'info' } ) ;
76+ consumer . attach ( ) ;
7477 const logger = new Logger ( ) ;
75- assert . throws ( ( ) => {
76- logger . info ( { userId : 123 } ) ; // Missing msg
77- } , {
78- code : 'ERR_INVALID_ARG_TYPE' ,
79- } ) ;
78+ try {
79+ assert . throws ( ( ) => {
80+ logger . info ( { userId : 123 } ) ; // Missing msg
81+ } , {
82+ code : 'ERR_INVALID_ARG_TYPE' ,
83+ } ) ;
84+ } finally {
85+ consumer . detach ( ) ;
86+ }
8087 } ) ;
8188
8289 it ( 'should throw when msg is not a string' , ( ) => {
90+ const stream = new TestStream ( ) ;
91+ const consumer = new JSONConsumer ( { stream, level : 'info' } ) ;
92+ consumer . attach ( ) ;
8393 const logger = new Logger ( ) ;
84- assert . throws ( ( ) => {
85- logger . info ( { msg : 123 } ) ; // msg is not a string
86- } , {
87- code : 'ERR_INVALID_ARG_TYPE' ,
88- } ) ;
94+ try {
95+ assert . throws ( ( ) => {
96+ logger . info ( { msg : 123 } ) ; // msg is not a string
97+ } , {
98+ code : 'ERR_INVALID_ARG_TYPE' ,
99+ } ) ;
100+ } finally {
101+ consumer . detach ( ) ;
102+ }
89103 } ) ;
90104
91105 it ( 'should accept string message without second argument' , ( ) => {
@@ -107,12 +121,19 @@ describe('Logger', () => {
107121
108122 describe ( 'invalid fields argument' , ( ) => {
109123 it ( 'should throw when fields is not an object' , ( ) => {
124+ const stream = new TestStream ( ) ;
125+ const consumer = new JSONConsumer ( { stream, level : 'info' } ) ;
126+ consumer . attach ( ) ;
110127 const logger = new Logger ( ) ;
111- assert . throws ( ( ) => {
112- logger . info ( 'message' , 'not an object' ) ;
113- } , {
114- code : 'ERR_INVALID_ARG_TYPE' ,
115- } ) ;
128+ try {
129+ assert . throws ( ( ) => {
130+ logger . info ( 'message' , 'not an object' ) ;
131+ } , {
132+ code : 'ERR_INVALID_ARG_TYPE' ,
133+ } ) ;
134+ } finally {
135+ consumer . detach ( ) ;
136+ }
116137 } ) ;
117138 } ) ;
118139} ) ;
0 commit comments