@@ -34,10 +34,10 @@ describe('AngularFirestoreDocument', () => {
34
34
35
35
describe ( 'valueChanges()' , ( ) => {
36
36
37
- it ( 'should get unwrapped snapshot' , async ( done : any ) => {
37
+ it ( 'should get unwrapped snapshot' , async ( done : DoneFn ) => {
38
38
const randomCollectionName = afs . firestore . collection ( 'a' ) . doc ( ) . id ;
39
- const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as firebase . firestore . DocumentReference < Stock > ;
40
- const stock = new AngularFirestoreDocument ( ref , afs ) ;
39
+ const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as DocumentReference < Stock > ;
40
+ const stock = new AngularFirestoreDocument < Stock > ( ref , afs ) ;
41
41
await stock . set ( FAKE_STOCK_DATA ) ;
42
42
const obs$ = stock . valueChanges ( ) ;
43
43
obs$ . pipe ( take ( 1 ) ) . subscribe ( async data => {
@@ -46,10 +46,9 @@ describe('AngularFirestoreDocument', () => {
46
46
} ) ;
47
47
} ) ;
48
48
49
- /* TODO(jamesdaniels): test is flaking, look into this
50
- it('should optionally map the doc ID to the emitted data object', async (done: any) => {
49
+ it ( 'should optionally map the doc ID to the emitted data object if doc exists' , async ( done : DoneFn ) => {
51
50
const randomCollectionName = afs . firestore . collection ( 'a' ) . doc ( ) . id ;
52
- const ref = afs.firestore.doc(`${randomCollectionName}/FAKE`);
51
+ const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as DocumentReference < Stock > ;
53
52
const stock = new AngularFirestoreDocument < Stock > ( ref , afs ) ;
54
53
await stock . set ( FAKE_STOCK_DATA ) ;
55
54
const idField = 'myCustomID' ;
@@ -59,36 +58,33 @@ describe('AngularFirestoreDocument', () => {
59
58
expect ( data ) . toEqual ( jasmine . objectContaining ( FAKE_STOCK_DATA ) ) ;
60
59
stock . delete ( ) . then ( done ) . catch ( done . fail ) ;
61
60
} ) ;
62
- });*/
61
+ } ) ;
62
+
63
+ it ( 'should not optionally map the doc ID to the emitted data object if doc does not exists' , async ( done : DoneFn ) => {
64
+ const randomCollectionName = afs . firestore . collection ( 'a' ) . doc ( ) . id ;
65
+ const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as DocumentReference < Stock > ;
66
+ const stock = new AngularFirestoreDocument < Stock > ( ref , afs ) ;
67
+ // await stock.set(FAKE_STOCK_DATA);
68
+ const idField = 'myCustomID' ;
69
+ const obs$ = stock . valueChanges ( { idField } ) ;
70
+ obs$ . pipe ( take ( 1 ) ) . subscribe ( async data => {
71
+ expect ( data ) . toBeUndefined ( ) ;
72
+ stock . delete ( ) . then ( done ) . catch ( done . fail ) ;
73
+ } ) ;
74
+ } ) ;
63
75
64
76
} ) ;
65
77
66
78
describe ( 'snapshotChanges()' , ( ) => {
67
79
68
- it ( 'should get action updates' , async ( done : any ) => {
80
+ it ( 'should get action updates' , async ( done : DoneFn ) => {
69
81
const randomCollectionName = randomName ( afs . firestore ) ;
70
82
const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as DocumentReference < Stock > ;
71
83
const stock = new AngularFirestoreDocument < Stock > ( ref , afs ) ;
72
84
await stock . set ( FAKE_STOCK_DATA ) ;
73
- const sub = stock
74
- . snapshotChanges ( )
75
- . subscribe ( async a => {
76
- sub . unsubscribe ( ) ;
77
- if ( a . payload . exists ) {
78
- expect ( a . payload . data ( ) ) . toEqual ( FAKE_STOCK_DATA ) ;
79
- stock . delete ( ) . then ( done ) . catch ( done . fail ) ;
80
- }
81
- } ) ;
82
- } ) ;
83
-
84
- it ( 'should get unwrapped snapshot' , async ( done : any ) => {
85
- const randomCollectionName = afs . firestore . collection ( 'a' ) . doc ( ) . id ;
86
- const ref = afs . firestore . doc ( `${ randomCollectionName } /FAKE` ) as DocumentReference < Stock > ;
87
- const stock = new AngularFirestoreDocument < Stock > ( ref , afs ) ;
88
- await stock . set ( FAKE_STOCK_DATA ) ;
89
- const obs$ = stock . valueChanges ( ) ;
90
- obs$ . pipe ( take ( 1 ) ) . subscribe ( async data => {
91
- expect ( data ) . toEqual ( FAKE_STOCK_DATA ) ;
85
+ const obs$ = stock . snapshotChanges ( ) ;
86
+ obs$ . pipe ( take ( 1 ) ) . subscribe ( async a => {
87
+ expect ( a . payload . data ( ) ) . toEqual ( FAKE_STOCK_DATA ) ;
92
88
stock . delete ( ) . then ( done ) . catch ( done . fail ) ;
93
89
} ) ;
94
90
} ) ;
0 commit comments