Skip to content

Commit 9ee7b4d

Browse files
committed
fix: table item title not readable if class.toString not overridden
(cherry picked from commit ee60db1)
1 parent f83a70f commit 9ee7b4d

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/table/table-item.class.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { TableItem } from "./index";
2+
3+
describe("TableItem", () => {
4+
it("should use title if defined", () => {
5+
let tableItem = new TableItem({data: 6, title: "title"});
6+
7+
expect(tableItem.title).toEqual("title");
8+
});
9+
10+
it("should use data if string", () => {
11+
let tableItem = new TableItem({data: "data"});
12+
13+
expect(tableItem.title).toEqual("data");
14+
});
15+
16+
it("should use toString for native elements", () => {
17+
let tableItem = new TableItem({data: true});
18+
19+
expect(tableItem.title).toEqual("true");
20+
});
21+
22+
it("should use empty if no data", () => {
23+
let tableItem = new TableItem({});
24+
25+
expect(tableItem.title).toEqual("");
26+
});
27+
28+
it("should not use toString if not overridden", () => {
29+
let tableItem = new TableItem({data: {}});
30+
31+
expect(tableItem.title).toEqual("");
32+
});
33+
34+
it("should not use toString if not overridden", () => {
35+
class TestClass {
36+
constructor(public i = 0) {
37+
}
38+
}
39+
let tableItem = new TableItem({data: new TestClass()});
40+
41+
expect(tableItem.title).toEqual("");
42+
});
43+
44+
45+
it("should not use toString if not overridden", () => {
46+
class TestClass {
47+
constructor(public i: number) {
48+
}
49+
toString(): string {
50+
return `${this.i}`;
51+
}
52+
}
53+
let tableItem = new TableItem({data: new TestClass(4)});
54+
55+
expect(tableItem.title).toEqual("4");
56+
});
57+
});

src/table/table-item.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class TableItem {
121121

122122
if (
123123
this.data.toString &&
124-
this.data.constructor !== ({}).constructor
124+
this.data.toString !== ({}).toString
125125
) {
126126
return this.data.toString();
127127
}

0 commit comments

Comments
 (0)