Skip to content

Commit

Permalink
fix: add well known symbol method (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevRichter committed Oct 18, 2023
1 parent 4bd3c53 commit e84177b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/CalendarDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class CalendarDate {
*/
readonly weekday!: number;

/**
* Customizes the default string description for instances of `CalendarDate`.
*/
get [Symbol.toStringTag]() {
return 'CalendarDate';
}

/**
* Throws an Error for invalid inputs.
*
Expand Down
8 changes: 8 additions & 0 deletions test/CalendarDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,12 @@ describe('CalendarDate', () => {
);
});
});

describe('Test of custom string description', () => {
test('the default string description of CalendarDate should be CalendarDate', () => {
const dateInstance = new CalendarDate('2021-01-01');
const tag = Object.prototype.toString.call(dateInstance);
expect(tag).toBe('[object CalendarDate]');
});
});
});

0 comments on commit e84177b

Please sign in to comment.