File tree Expand file tree Collapse file tree 3 files changed +82
-26
lines changed Expand file tree Collapse file tree 3 files changed +82
-26
lines changed Original file line number Diff line number Diff line change 11const  { resolve}  =  require ( 'path' ) 
22const  { render}  =  require ( '../pure' ) 
33
4- test ( 'Should handle argument passing ' ,  async  ( )  =>  { 
4+ test ( 'toBeInTheConsole should pass when something is in console ' ,  async  ( )  =>  { 
55  const  { findByText}  =  await  render ( 'node' ,  [ 
66    resolve ( __dirname ,  './execute-scripts/list-args.js' ) , 
77    '--version' , 
88  ] ) 
99
10-   expect ( await  findByText ( '--version' ) ) . toBeInTheConsole ( ) 
10+   await  expect ( 
11+       ( async  ( )  =>  expect ( await  findByText ( '--version' ) ) . toBeInTheConsole ( ) ) ( ) 
12+   ) . resolves . not . toThrow ( ) 
13+ } ) 
14+ 
15+ test ( 'toBeInTheConsole should fail when something is not console' ,  async  ( )  =>  { 
16+   const  { queryByText}  =  await  render ( 'node' ,  [ 
17+     resolve ( __dirname ,  './execute-scripts/list-args.js' ) , 
18+     '--version' , 
19+   ] ) 
20+ 
21+   expect ( ( )  =>  expect ( queryByText ( 'NotHere' ) ) . toBeInTheConsole ( ) ) . toThrow ( / v a l u e   m u s t   b e   a   T e s t I n s t a n c e / ) 
1122} ) 
Original file line number Diff line number Diff line change 1- import  { 
2-   ensureNoExpected , 
3-   matcherHint , 
4-   printReceived , 
5- }  from  'jest-matcher-utils' ; 
1+ import  { checkCliInstance }  from  "./utils" ; 
62
7- export  function  toBeInTheConsole ( instance ,  expected )  { 
8-   // This code is 1:1 with Jest's built-in "ToBeTruthy" 
9-   // @see  https://github.com/facebook/jest/blob/main/packages/expect/src/matchers.ts#L398-L414 
10-   const  matcherName  =  'toBeTruthy' ; 
11-   const  options  =  { 
3+ export  function  toBeInTheConsole ( instance )  { 
4+   // eslint-disable-next-line @babel/no-invalid-this 
5+   if  ( instance  !==  null  ||  ! this . isNot )  { 
126    // eslint-disable-next-line @babel/no-invalid-this 
13-     isNot : this . isNot , 
14-     // eslint-disable-next-line @babel/no-invalid-this 
15-     promise : this . promise , 
16-   } ; 
17-   ensureNoExpected ( expected ,  matcherName ,  options ) ; 
18- 
19-   const  pass  =  ! ! instance ; 
20- 
21-   const  message  =  ( )  => 
22-       `${ matcherHint ( matcherName ,  undefined ,  '' ,  options )   
23-       }  \n\n`+ 
24-       `Received: ${ printReceived ( instance ) }  ; 
25- 
26-   return  { message,  pass} ; 
7+     checkCliInstance ( instance ,  toBeInTheConsole ,  this ) 
8+   } 
9+ 
10+   // Assuming it passed above, it must have passed 
11+   return  { 
12+     pass : true , 
13+     message : ( )  =>  [ ] 
14+   } 
2715} 
Original file line number Diff line number Diff line change 1+ class  GenericTypeError  extends  Error  { 
2+     constructor ( expectedString ,  received ,  matcherFn ,  context )  { 
3+         super ( ) 
4+ 
5+         /* istanbul ignore next */ 
6+         if  ( Error . captureStackTrace )  { 
7+             Error . captureStackTrace ( this ,  matcherFn ) 
8+         } 
9+         let  withType  =  '' 
10+         try  { 
11+             withType  =  context . utils . printWithType ( 
12+                 'Received' , 
13+                 received , 
14+                 context . utils . printReceived , 
15+             ) 
16+         }  catch  ( e )  { 
17+             // Can throw for Document: 
18+             // https://github.com/jsdom/jsdom/issues/2304 
19+         } 
20+         this . message  =  [ 
21+             context . utils . matcherHint ( 
22+                 `${ context . isNot  ? '.not'  : '' } ${ matcherFn . name }  , 
23+                 'received' , 
24+                 '' , 
25+             ) , 
26+             '' , 
27+             // eslint-disable-next-line @babel/new-cap 
28+             `${ context . utils . RECEIVED_COLOR (  
29+                 'received' ,  
30+             ) }   value must ${ expectedString } , 
31+             withType , 
32+         ] . join ( '\n' ) 
33+     } 
34+ } 
35+ 
36+ class  CliInstanceTypeError  extends  GenericTypeError  { 
37+     constructor ( ...args )  { 
38+         super ( 'be a TestInstance' ,  ...args ) 
39+     } 
40+ } 
41+ 
42+ /** 
43+  * @param  {TestInstance } cliInstance 
44+  * @param  args 
45+  */ 
46+ function  checkCliInstance ( cliInstance ,  ...args )  { 
47+        if  ( 
48+         ! ( cliInstance  &&  cliInstance . process  &&  cliInstance . process . stdout ) 
49+     )  { 
50+         throw  new  CliInstanceTypeError ( cliInstance ,  ...args ) 
51+     } 
52+ } 
53+ 
54+ export  { 
55+     CliInstanceTypeError , 
56+     checkCliInstance , 
57+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments