From c6763039c19a48e9302a8032353b7c8c9d28b1cc Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Thu, 6 Apr 2023 22:43:56 +0800 Subject: [PATCH] fix: tests --- src/lib/columns.newDataColumn.test.ts | 11 ++++++----- src/lib/columns.ts | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/columns.newDataColumn.test.ts b/src/lib/columns.newDataColumn.test.ts index 135f6dd..576c875 100644 --- a/src/lib/columns.newDataColumn.test.ts +++ b/src/lib/columns.newDataColumn.test.ts @@ -28,11 +28,12 @@ it('falls back on the string accessor as id', () => { expect(actual.id).toBe('firstName'); }); -it('throws if id is undefined without string accessor', () => { +it('throws if id is undefined without string accessor or header', () => { expect(() => { new DataColumn({ - header: 'First Name', - accessor: (u) => u.firstName, - }); - }).toThrowError('A column id or string accessor is required'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + accessor: (u: any) => u.firstName, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any); + }).toThrowError('A column id, string accessor, or header is required'); }); diff --git a/src/lib/columns.ts b/src/lib/columns.ts index 0d10795..203f5fb 100644 --- a/src/lib/columns.ts +++ b/src/lib/columns.ts @@ -136,7 +136,8 @@ export class DataColumn< if (id === undefined && this.accessorKey === undefined && header === undefined) { throw new Error('A column id, string accessor, or header is required'); } - this.id = (id ?? this.accessorKey ? String(this.accessorKey) : String(header)) as Id; + const accessorKeyId = typeof this.accessorKey === 'string' ? this.accessorKey : null; + this.id = (id ?? accessorKeyId ?? String(header)) as Id; } // eslint-disable-next-line @typescript-eslint/no-explicit-any