Skip to content

Commit 5b06306

Browse files
committed
test(ids): make sure id is kept in documents
Also make sure id is non enumerable, writable, nor configurable
1 parent 14a6c55 commit 5b06306

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function isObject (o) {
1010
}
1111

1212
export function extractRefs (doc, path = '', result = [{}, {}]) {
13+
const idDescriptor = Object.getOwnPropertyDescriptor(doc, 'id')
14+
if (idDescriptor && !idDescriptor.enumerable) {
15+
Object.defineProperty(result[0], 'id', idDescriptor)
16+
}
1317
return Object.keys(doc).reduce((tot, key) => {
1418
const ref = doc[key]
1519
// if it's a ref

test/document.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vuefire from '../src'
22
import {
33
db,
44
tick,
5+
Key,
56
Vue
67
} from './helpers'
78

@@ -41,3 +42,15 @@ test('updates a document', async () => {
4142
await document.update({ bar: 'bar' })
4243
expect(vm.item).toEqual({ foo: 'foo', bar: 'bar' })
4344
})
45+
46+
test('adds non-enumerable id', async () => {
47+
document = collection.doc(new Key('some-id'))
48+
await document.update({ foo: 'foo' })
49+
await vm.$bind('item', document)
50+
expect(Object.getOwnPropertyDescriptor(vm.item, 'id')).toEqual({
51+
configurable: false,
52+
enumerable: false,
53+
writable: false,
54+
value: 'some-id'
55+
})
56+
})

0 commit comments

Comments
 (0)