@@ -28,9 +28,9 @@ import {
2828 docData ,
2929 collectionData ,
3030} from '../dist/firestore/lite' ;
31- import { map , take , skip } from 'rxjs/operators' ;
31+ import { map } from 'rxjs/operators' ;
3232import { default as TEST_PROJECT , firestoreEmulatorPort } from './config' ;
33- import { doc as firestoreDoc , getDocs , collection as firestoreCollection , getDoc , Firestore as FirebaseFirestore , CollectionReference , getFirestore , DocumentReference , connectFirestoreEmulator , doc , setDoc , collection as baseCollection } from 'firebase/firestore/lite' ;
33+ import { doc as firestoreDoc , getDocs , collection as firestoreCollection , getDoc , Firestore as FirebaseFirestore , CollectionReference , getFirestore , DocumentReference , connectFirestoreEmulator , doc , setDoc , collection as baseCollection , QueryDocumentSnapshot } from 'firebase/firestore/lite' ;
3434import { initializeApp , deleteApp , FirebaseApp } from 'firebase/app' ;
3535
3636const createId = ( ) : string => Math . random ( ) . toString ( 36 ) . substring ( 5 ) ;
@@ -105,6 +105,46 @@ describe('RxFire firestore/lite', () => {
105105 } ) ;
106106 } ) ;
107107
108+
109+ describe ( 'collection w/converter' , ( ) => {
110+ /**
111+ * This is a simple test to see if the collection() method
112+ * correctly emits snapshots.
113+ *
114+ * The test seeds two "people" into the collection. RxFire
115+ * creats an observable with the `collection()` method and
116+ * asserts that the two "people" are in the array.
117+ */
118+ it ( 'should emit snapshots' , async ( done : jest . DoneCallback ) => {
119+ const { colRef, expectedNames} = await seedTest ( firestore ) ;
120+
121+ class Folk {
122+ constructor ( public name : string ) { }
123+ static fromFirestore ( snap : QueryDocumentSnapshot ) {
124+ const name = snap . data ( ) . name ;
125+ if ( name !== 'Shannon' ) {
126+ return new Folk ( `${ snap . data ( ) . name } !` ) ;
127+ } else {
128+ return undefined ;
129+ }
130+ }
131+ static toFirestore ( ) {
132+ return { } ;
133+ }
134+ static collection = colRef . withConverter ( Folk ) ;
135+ }
136+
137+ collection ( Folk . collection )
138+ . subscribe ( docs => {
139+ const names = docs . map ( doc => doc . data ( ) ?. name ) ;
140+ const classes = docs . map ( doc => doc . data ( ) ?. constructor ?. name ) ;
141+ expect ( names ) . toEqual ( [ 'David!' , undefined ] ) ;
142+ expect ( classes ) . toEqual ( [ 'Folk' , undefined ] ) ;
143+ done ( ) ;
144+ } ) ;
145+ } ) ;
146+ } ) ;
147+
108148 describe ( 'Data Mapping Functions' , ( ) => {
109149 /**
110150 * The `unwrap(id)` method will map a collection to its data payload and map the doc ID to a the specificed key.
0 commit comments