diff --git a/src/components/BrowserCell/BrowserCell.react.js b/src/components/BrowserCell/BrowserCell.react.js
index 74cbe7ca04..52a6d0c05c 100644
--- a/src/components/BrowserCell/BrowserCell.react.js
+++ b/src/components/BrowserCell/BrowserCell.react.js
@@ -148,12 +148,13 @@ export default class BrowserCell extends Component {
this.copyableValue = content = JSON.stringify(this.props.value);
}
} else if (this.props.type === 'Date') {
- if (typeof value === 'object' && this.props.value.__type) {
- this.props.value = new Date(this.props.value.iso);
- } else if (typeof value === 'string') {
- this.props.value = new Date(this.props.value);
+ let dateValue = this.props.value;
+ if (typeof dateValue === 'object' && dateValue.__type) {
+ dateValue = new Date(dateValue.iso);
+ } else if (typeof dateValue === 'string') {
+ dateValue = new Date(dateValue);
}
- this.copyableValue = content = dateStringUTC(this.props.value);
+ this.copyableValue = content = dateStringUTC(dateValue);
} else if (this.props.type === 'Boolean') {
this.copyableValue = content = this.props.value ? 'True' : 'False';
} else if (this.props.type === 'Object' || this.props.type === 'Bytes') {
@@ -206,6 +207,8 @@ export default class BrowserCell extends Component {
'Relation'
);
this.copyableValue = undefined;
+ } else if (this.props.value instanceof Date) {
+ this.copyableValue = content = dateStringUTC(this.props.value);
}
this.onContextMenu = this.onContextMenu.bind(this);
diff --git a/src/lib/tests/BrowserCell.test.js b/src/lib/tests/BrowserCell.test.js
index e2ea22b589..15427e3eb0 100644
--- a/src/lib/tests/BrowserCell.test.js
+++ b/src/lib/tests/BrowserCell.test.js
@@ -49,4 +49,26 @@ describe('BrowserCell', () => {
expect(component.props.className).toContain('required');
});
});
+
+ describe('Date value in a non-Date column (issue #1927)', () => {
+ it('should render a Date value as a string instead of crashing', () => {
+ let component;
+ expect(() => {
+ component = renderer
+ .create()
+ .toJSON();
+ }).not.toThrow();
+ expect(typeof component.children[0]).toBe('string');
+ });
+
+ it('should render a Date-typed column given a date string without crashing', () => {
+ let component;
+ expect(() => {
+ component = renderer
+ .create()
+ .toJSON();
+ }).not.toThrow();
+ expect(typeof component.children[0]).toBe('string');
+ });
+ });
});