From 253401f35e00a3d88bd8a8e10a7d01dc07225921 Mon Sep 17 00:00:00 2001 From: Byron Dover Date: Sun, 22 Jan 2017 17:02:05 -0800 Subject: [PATCH] fix(utils): Make object $key and $exists properties non-enumerable --- src/database/firebase_object_factory.spec.ts | 8 ++++---- src/database/firebase_object_observable.spec.ts | 2 +- src/utils.ts | 11 +++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/database/firebase_object_factory.spec.ts b/src/database/firebase_object_factory.spec.ts index 7d677d793..078ca6bdb 100644 --- a/src/database/firebase_object_factory.spec.ts +++ b/src/database/firebase_object_factory.spec.ts @@ -81,12 +81,12 @@ describe('FirebaseObjectFactory', () => { it('should emit unwrapped data by default', (done: any) => { - ref.set({ data: 'bar' }, () => { + const fixtureData = { data: 'bar' }; + ref.set(fixtureData, () => { subscription = observable.subscribe(unwrapped => { if (!unwrapped) return; - const expectedObject = { $key: ref.key, data: 'bar' }; - expect(unwrapped.$key).toEqual(expectedObject.$key); - expect(unwrapped.data).toEqual(expectedObject.data); + expect(unwrapped.$key).toEqual(ref.key); + expect(unwrapped).toEqual(fixtureData); expect(unwrapped.$exists()).toEqual(true); done(); }); diff --git a/src/database/firebase_object_observable.spec.ts b/src/database/firebase_object_observable.spec.ts index b963db3c7..3e390fa55 100644 --- a/src/database/firebase_object_observable.spec.ts +++ b/src/database/firebase_object_observable.spec.ts @@ -30,7 +30,7 @@ describe('FirebaseObjectObservable', () => { }); inject([FirebaseApp, AngularFire], (firebaseApp: firebase.app.App, _af: AngularFire) => { app = firebaseApp; - ref = firebase.database().ref() + ref = firebase.database().ref(); O = new FirebaseObjectObservable((observer:Observer) => { }, ref); })(); diff --git a/src/utils.ts b/src/utils.ts index 4cf14eebe..6da9518ee 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -57,10 +57,13 @@ export function unwrapMapFn (snapshot:firebase.database.DataSnapshot): AFUnwrapp $value: unwrapped }; } - unwrapped.$key = snapshot.ref.key; - unwrapped.$exists = () => { - return snapshot.exists(); - }; + Object.defineProperty(unwrapped, '$key', {value: snapshot.ref.key, enumerable: false}); + Object.defineProperty(unwrapped, '$exists', { + value: () => { + return snapshot.exists(); + }, + enumerable: false + }); return unwrapped; }