@@ -50,7 +50,7 @@ test("instanceof", () => {
5050 "class myClass {} let inst = new myClass(); return inst instanceof myClass;" ,
5151 ) ;
5252
53- expect ( result ) . toBeTruthy ( ) ;
53+ expect ( result ) . toBe ( true ) ;
5454} ) ;
5555
5656test ( "instanceof inheritance" , ( ) => {
@@ -60,7 +60,7 @@ test("instanceof inheritance", () => {
6060 let inst = new childClass(); return inst instanceof myClass;
6161 ` ) ;
6262
63- expect ( result ) . toBeTruthy ( ) ;
63+ expect ( result ) . toBe ( true ) ;
6464} ) ;
6565
6666test ( "instanceof inheritance false" , ( ) => {
@@ -73,15 +73,33 @@ test("instanceof inheritance false", () => {
7373 expect ( result ) . toBe ( false ) ;
7474} ) ;
7575
76+ test ( "{} instanceof Object" , ( ) => {
77+ const result = util . transpileAndExecute ( "return {} instanceof Object;" ) ;
78+
79+ expect ( result ) . toBe ( true ) ;
80+ } ) ;
81+
82+ test ( "function instanceof Object" , ( ) => {
83+ const result = util . transpileAndExecute ( "return (() => {}) instanceof Object;" ) ;
84+
85+ expect ( result ) . toBe ( true ) ;
86+ } ) ;
87+
7688test ( "null instanceof Object" , ( ) => {
77- const result = util . transpileAndExecute ( "return (<any> null) instanceof Object;" ) ;
89+ const result = util . transpileAndExecute ( "return (null as any ) instanceof Object;" ) ;
7890
7991 expect ( result ) . toBe ( false ) ;
8092} ) ;
8193
94+ test ( "instanceof undefined" , ( ) => {
95+ expect ( ( ) => {
96+ util . transpileAndExecute ( "return {} instanceof (undefined as any);" ) ;
97+ } ) . toThrow ( "Right-hand side of 'instanceof' is not an object" ) ;
98+ } ) ;
99+
82100test ( "null instanceof Class" , ( ) => {
83101 const result = util . transpileAndExecute (
84- "class myClass {} return (<any> null) instanceof myClass;" ,
102+ "class myClass {} return (null as any ) instanceof myClass;" ,
85103 ) ;
86104
87105 expect ( result ) . toBe ( false ) ;
@@ -108,5 +126,23 @@ test("instanceof export", () => {
108126 "result" ,
109127 ) ;
110128
111- expect ( result ) . toBeTruthy ( ) ;
129+ expect ( result ) . toBe ( true ) ;
130+ } ) ;
131+
132+ test ( "instanceof Symbol.hasInstance" , ( ) => {
133+ const result = util . transpileAndExecute ( `
134+ class myClass {
135+ static [Symbol.hasInstance]() {
136+ return false;
137+ }
138+ }
139+
140+ const inst = new myClass();
141+ const isInstanceOld = inst instanceof myClass;
142+ myClass[Symbol.hasInstance] = () => true;
143+ const isInstanceNew = inst instanceof myClass;
144+ return isInstanceOld !== isInstanceNew;
145+ ` ) ;
146+
147+ expect ( result ) . toBe ( true ) ;
112148} ) ;
0 commit comments