@@ -28,3 +28,96 @@ test.each(["[]", '[["a", 1], ["b", 2]]', '[["a", 1], ["a", 2]]', 'new Map([["foo
2828 util . testExpression `Object.fromEntries(${ entries } )` . expectToMatchJsResult ( ) ;
2929 }
3030) ;
31+
32+ describe ( ".toString()" , ( ) => {
33+ const toStringDeclaration = `
34+ function toString(value: object) {
35+ const result = value.toString();
36+ return result === "[object Object]" || result.startsWith("table: ") ? "table" : result;
37+ }
38+ ` ;
39+
40+ test ( "class override" , ( ) => {
41+ util . testFunction `
42+ ${ toStringDeclaration }
43+ class A {
44+ public toString() {
45+ return "A";
46+ }
47+ }
48+
49+ return toString(new A());
50+ ` . expectToMatchJsResult ( ) ;
51+ } ) ;
52+
53+ test ( "inherited class override" , ( ) => {
54+ util . testFunction `
55+ ${ toStringDeclaration }
56+ class A {
57+ public toString() {
58+ return "A";
59+ }
60+ }
61+
62+ class B extends A {}
63+
64+ return { A: toString(new A()), B: toString(new B()) };
65+ ` . expectToMatchJsResult ( ) ;
66+ } ) ;
67+
68+ test ( "don't affect inherited class" , ( ) => {
69+ util . testFunction `
70+ ${ toStringDeclaration }
71+ class A {}
72+
73+ class B extends A {
74+ public toString() {
75+ return "B";
76+ }
77+ }
78+
79+ return { A: toString(new A()), B: toString(new B()) };
80+ ` . expectToMatchJsResult ( ) ;
81+ } ) ;
82+
83+ test ( "override inherited class override" , ( ) => {
84+ util . testFunction `
85+ ${ toStringDeclaration }
86+ class A {
87+ public toString() {
88+ return "A";
89+ }
90+ }
91+
92+ class B extends A {
93+ public toString() {
94+ return "B";
95+ }
96+ }
97+
98+ return { A: toString(new A()), B: toString(new B()) };
99+ ` . expectToMatchJsResult ( ) ;
100+ } ) ;
101+ } ) ;
102+
103+ describe ( ".hasOwnProperty()" , ( ) => {
104+ test ( "class field" , ( ) => {
105+ util . testFunction `
106+ class A {
107+ public field = true;
108+ }
109+
110+ return new A().hasOwnProperty("field");
111+ ` . expectToMatchJsResult ( ) ;
112+ } ) ;
113+
114+ test ( "class method" , ( ) => {
115+ util . testFunction `
116+ class A {
117+ public method() {}
118+ }
119+
120+ return new A().hasOwnProperty("method");
121+ ` . expectToMatchJsResult ( ) ;
122+ } ) ;
123+ } ) ;
0 commit comments