diff --git a/src/utils.js b/src/utils.js index 4f3b486a..4ab0702a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -27,6 +27,8 @@ export function extractRefs (doc, oldDoc, path = '', result = [{}, {}]) { // TODO handle array tot[0][key] = Array(ref.length).fill(null) extractRefs(ref, oldDoc[key], path + key + '.', [tot[0][key], tot[1]]) + } else if (ref instanceof Date) { + tot[0][key] = ref } else if (isObject(ref)) { tot[0][key] = {} extractRefs(ref, oldDoc[key], path + key + '.', [tot[0][key], tot[1]]) diff --git a/test/utils.spec.js b/test/utils.spec.js index 83f973ba..42cc61e2 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -54,6 +54,17 @@ test('extract refs from document', () => { }) }) +test('leave Date objects alone when extracting refs', () => { + const d = new Date() + const [doc, refs] = extractRefs({ + foo: 1, + bar: d + }) + expect(doc.foo).toEqual(1) + expect(doc.bar).toEqual(d) + expect(refs).toEqual({}) +}) + test('extract object nested refs from document', () => { const [noRefsDoc, refs] = extractRefs({ obj: {