@@ -318,6 +318,7 @@ test('spy functions can be bound', (t) => {
318318 assert . strictEqual ( sum . mock . restore ( ) , undefined ) ;
319319 assert . strictEqual ( sum . bind ( 0 ) ( 2 , 11 ) , 13 ) ;
320320} ) ;
321+
321322test ( 'mocks prototype methods on an instance' , async ( t ) => {
322323 class Runner {
323324 async someTask ( msg ) {
@@ -345,6 +346,13 @@ test('mocks prototype methods on an instance', async (t) => {
345346 assert . strictEqual ( call . target , undefined ) ;
346347 assert . strictEqual ( call . this , obj ) ;
347348
349+ const obj2 = new Runner ( ) ;
350+ // Ensure that a brand new instance is not mocked
351+ assert . strictEqual (
352+ obj2 . someTask . mock ,
353+ undefined
354+ ) ;
355+
348356 assert . strictEqual ( obj . someTask . mock . restore ( ) , undefined ) ;
349357 assert . strictEqual ( await obj . method ( msg ) , msg ) ;
350358 assert . strictEqual ( obj . someTask . mock , undefined ) ;
@@ -381,6 +389,42 @@ test('spies on async static class methods', async (t) => {
381389 assert . strictEqual ( Runner . someTask . mock , undefined ) ;
382390} ) ;
383391
392+ test ( 'given null to a mock.method it throws a invalid argument error' , ( t ) => {
393+ assert . throws ( ( ) => t . mock . method ( null , { } ) , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
394+ } ) ;
395+
396+ test ( 'spy functions can be used on classes inheritance' , ( t ) => {
397+ class A {
398+ static someTask ( msg ) {
399+ return msg ;
400+ }
401+ static method ( msg ) {
402+ return this . someTask ( msg ) ;
403+ }
404+ }
405+ class B extends A { }
406+ class C extends B { }
407+
408+ const msg = 'ok' ;
409+ assert . strictEqual ( C . method ( msg ) , msg ) ;
410+
411+ t . mock . method ( C , C . someTask . name ) ;
412+ assert . strictEqual ( C . someTask . mock . calls . length , 0 ) ;
413+
414+ assert . strictEqual ( C . method ( msg ) , msg ) ;
415+
416+ const call = C . someTask . mock . calls [ 0 ] ;
417+
418+ assert . deepStrictEqual ( call . arguments , [ msg ] ) ;
419+ assert . strictEqual ( call . result , msg ) ;
420+ assert . strictEqual ( call . target , undefined ) ;
421+ assert . strictEqual ( call . this , C ) ;
422+
423+ assert . strictEqual ( C . someTask . mock . restore ( ) , undefined ) ;
424+ assert . strictEqual ( C . method ( msg ) , msg ) ;
425+ assert . strictEqual ( C . someTask . mock , undefined ) ;
426+ } ) ;
427+
384428test ( 'mocked functions report thrown errors' , ( t ) => {
385429 const testError = new Error ( 'test error' ) ;
386430 const fn = t . mock . fn ( ( ) => {
0 commit comments