@@ -289,6 +289,57 @@ describe('Karma', function () {
289289 assert . equal ( promptCalled ,  true ) 
290290 assert . equal ( promptResult ,  'user-input' ) 
291291 } ) 
292+ 
293+  it ( 'should patch the console if captureConsole is true' ,  function  ( )  { 
294+  sinon . spy ( ck ,  'log' ) 
295+  ck . config . captureConsole  =  true 
296+ 
297+  var  mockWindow  =  { 
298+  console : { 
299+  log : function  ( )  { } 
300+  } 
301+  } 
302+ 
303+  ck . setupContext ( mockWindow ) 
304+  mockWindow . console . log ( 'What?' ) 
305+  assert ( ck . log . calledWith ( 'log' ) ) 
306+  assert ( ck . log . args [ 0 ] [ 1 ] [ 0 ]  ===  'What?' ) 
307+  } ) 
308+ 
309+  it ( 'should not patch the console if captureConsole is false' ,  function  ( )  { 
310+  sinon . spy ( ck ,  'log' ) 
311+  ck . config . captureConsole  =  false 
312+ 
313+  var  mockWindow  =  { 
314+  console : { 
315+  log : function  ( )  { } 
316+  } 
317+  } 
318+ 
319+  ck . setupContext ( mockWindow ) 
320+  mockWindow . console . log ( 'hello' ) 
321+  assert ( ! ck . log . called ) 
322+  } ) 
323+ 
324+  it ( 'should not allow broken console methods to break tests (if captureConsole is true)' ,  function  ( )  { 
325+  sinon . spy ( ck ,  'log' ) 
326+  ck . config . captureConsole  =  true 
327+ 
328+  var  mockWindow  =  { 
329+  console : { 
330+  log : function  ( )  { 
331+  throw  new  Error ( 'I am a broken console.log method.' ) 
332+  } 
333+  } 
334+  } 
335+ 
336+  ck . setupContext ( mockWindow ) 
337+  mockWindow . console . log ( 'What?' ) 
338+  assert ( ck . log . calledWith ( 'log' ) ) 
339+  assert . equal ( ck . log . args [ 0 ] [ 1 ] [ 0 ] ,  'What?' ) 
340+  assert ( ck . log . calledWith ( 'warn' ) ) 
341+  assert ( / ^ C o n s o l e   m e t h o d   l o g   t h r e w : [ \s \S ] + I   a m   a   b r o k e n   c o n s o l e \. l o g   m e t h o d / . test ( ck . log . args [ 1 ] [ 1 ] [ 0 ] ) ) 
342+  } ) 
292343 } ) 
293344
294345 describe ( 'complete' ,  function  ( )  { 
@@ -343,37 +394,6 @@ describe('Karma', function () {
343394 clock . tick ( 10 ) 
344395 } ) 
345396
346-  it ( 'should patch the console if captureConsole is true' ,  function  ( )  { 
347-  sinon . spy ( ck ,  'log' ) 
348-  ck . config . captureConsole  =  true 
349- 
350-  var  mockWindow  =  { 
351-  console : { 
352-  log : function  ( )  { } 
353-  } 
354-  } 
355- 
356-  ck . setupContext ( mockWindow ) 
357-  mockWindow . console . log ( 'What?' ) 
358-  assert ( ck . log . calledWith ( 'log' ) ) 
359-  assert ( ck . log . args [ 0 ] [ 1 ] [ 0 ]  ===  'What?' ) 
360-  } ) 
361- 
362-  it ( 'should not patch the console if captureConsole is false' ,  function  ( )  { 
363-  sinon . spy ( ck ,  'log' ) 
364-  ck . config . captureConsole  =  false 
365- 
366-  var  mockWindow  =  { 
367-  console : { 
368-  log : function  ( )  { } 
369-  } 
370-  } 
371- 
372-  ck . setupContext ( mockWindow ) 
373-  mockWindow . console . log ( 'hello' ) 
374-  assert ( ! ck . log . called ) 
375-  } ) 
376- 
377397 it ( 'should clear context window upon complete when clearContext config is true' ,  function  ( )  { 
378398 var  config  =  ck . config  =  { 
379399 clearContext : true 
0 commit comments