|
| 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 | +}); |
0 commit comments