Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmylee committed Apr 6, 2023
1 parent 2e3f9f1 commit c676303
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/lib/columns.newDataColumn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>({
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');
});
3 changes: 2 additions & 1 deletion src/lib/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c676303

Please sign in to comment.