@@ -52,6 +52,19 @@ const BASE_DIFFS = [
5252 [ "date" , TODAY , new Date ( "2021-12-10T00:00:00.001Z" ) ]
5353] ;
5454
55+ class Car {
56+
57+ private readonly model : string ;
58+
59+ constructor ( model : string ) {
60+ this . model = model ;
61+ }
62+
63+ public showModel ( ) : string {
64+ return this . model ;
65+ }
66+ }
67+
5568function truthyAsText ( value : typeof TRUTHY_VALUES [ number ] ) : string {
5669 if ( Array . isArray ( value ) && value . length === 0 ) {
5770 return "Empty array" ;
@@ -263,6 +276,40 @@ describe("[Unit] Assertion.test.ts", () => {
263276 } ) ;
264277 } ) ;
265278
279+ describe ( ".toBeInstanceOf" , ( ) => {
280+ context ( "when the value is an instance of the constructor" , ( ) => {
281+ const variants = [
282+ [ new Date ( ) , Date ] ,
283+ [ new Error ( "failed!" ) , Error ] ,
284+ [ new Car ( "Pontiac GT-37" ) , Car ]
285+ ] as const ;
286+
287+ variants . forEach ( ( [ value , Constructor ] ) => {
288+ it ( `[Instance: ${ Constructor . name } ]: returns the assertion instance` , ( ) => {
289+ const test = new Assertion ( value ) ;
290+
291+ assert . deepStrictEqual ( test . toBeInstanceOf ( Constructor ) , test ) ;
292+ assert . throws ( ( ) => test . not . toBeInstanceOf ( Constructor ) , {
293+ message : `Expected value NOT to be an instance of <${ Constructor . name } >` ,
294+ name : AssertionError . name
295+ } ) ;
296+ } ) ;
297+ } ) ;
298+ } ) ;
299+
300+ context ( "when the value in not an instance of the constructor" , ( ) => {
301+ it ( "throws an assertion error" , ( ) => {
302+ const test = new Assertion ( new Date ( ) ) ;
303+
304+ assert . throws ( ( ) => test . toBeInstanceOf ( Car ) , {
305+ message : "Expected value to be an instance of <Car>" ,
306+ name : AssertionError . name
307+ } ) ;
308+ assert . deepStrictEqual ( test . not . toBeInstanceOf ( Car ) , test ) ;
309+ } ) ;
310+ } ) ;
311+ } ) ;
312+
266313 describe ( ".toBeEqual" , ( ) => {
267314 context ( "when the value is referentially, shallow, and deep equal" , ( ) => {
268315 [
0 commit comments