Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/cli-repl/src/format-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ for (const colors of [ false, true ]) {
});
});

context('when the result is a date', () => {
it('returns the inspection', () => {
expect(format({ value: new Date(1234567890000) })).to.include('ISODate("2009-02-13T23:31:30.000Z")');
expect(format({ value: new Date(NaN) })).to.include('Invalid Date');
});
});

context('when the result is a Cursor', () => {
context('when the Cursor is not empty', () => {
it('returns the inspection', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli-repl/src/format-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ function removeUndefinedValues<T>(obj: T) {
return Object.fromEntries(Object.entries(obj).filter(keyValue => keyValue[1] !== undefined));
}

function dateInspect(this: Date): string {
function dateInspect(this: Date, depth: number, options: any): string {
if (isNaN(this.valueOf())) {
return options.stylize('Invalid Date', 'date');
}
return `ISODate("${this.toISOString()}")`;
}

Expand Down