@@ -32,8 +32,6 @@ const {
3232 increment,
3333 initializeFirestore,
3434} = firestoreModular ;
35- const { getApp } = modular ;
36-
3735
3836// Used for testing the FirestoreDataConverter.
3937class Post {
@@ -83,18 +81,27 @@ const postConverterMerge = {
8381 } ,
8482} ;
8583
84+ // v8 compatibility helper functions
85+ function modifyIgnoreUndefinedProperties ( db , value ) {
86+ // JS SDK settings can only be called once
87+ if ( Platform . other ) {
88+ db . _settings . ignoreUndefinedProperties = value ;
89+ } else {
90+ db . settings ( { ignoreUndefinedProperties : value } ) ;
91+ }
92+ }
93+
94+ // modular helper functions
8695function withTestDb ( fn ) {
8796 return fn ( getFirestore ( ) ) ;
8897}
8998
9099async function withModifiedUndefinedPropertiesTestDb ( fn ) {
91- const db = await initializeFirestore ( getApp ( ) , {
92- ignoreUndefinedProperties : false ,
93- } ) ;
100+ const db = getFirestore ( ) ;
101+ const previousValue = db . _settings . ignoreUndefinedProperties ;
102+ initializeFirestore ( db . app , { ignoreUndefinedProperties : false } ) ;
94103 await fn ( db ) ;
95- await initializeFirestore ( getApp ( ) , {
96- ignoreUndefinedProperties : true ,
97- } ) ;
104+ initializeFirestore ( db . app , { ignoreUndefinedProperties : previousValue } ) ;
98105}
99106
100107function withTestCollection ( fn ) {
@@ -115,7 +122,7 @@ function withTestCollectionAndInitialData(data, fn) {
115122 } ) ;
116123}
117124
118- describe ( 'firestore.Transaction ' , function ( ) {
125+ describe ( 'firestore.withConverter ' , function ( ) {
119126 describe ( 'v8 compatibility' , function ( ) {
120127 beforeEach ( async function beforeEachTest ( ) {
121128 // @ts -ignore
@@ -289,7 +296,9 @@ describe('firestore.Transaction', function () {
289296
290297 it ( 'requires the correct converter for Partial usage' , async function ( ) {
291298 const db = firebase . firestore ( ) ;
292- db . settings ( { ignoreUndefinedProperties : false } ) ;
299+ const previousValue = db . _settings . ignoreUndefinedProperties ;
300+ modifyIgnoreUndefinedProperties ( db , false ) ;
301+
293302 const coll = db . collection ( 'posts' ) ;
294303 const ref = coll . doc ( 'post' ) . withConverter ( postConverter ) ;
295304 const batch = db . batch ( ) ;
@@ -300,7 +309,7 @@ describe('firestore.Transaction', function () {
300309 } catch ( error ) {
301310 error . message . should . containEql ( 'Unsupported field value: undefined' ) ;
302311 }
303- db . settings ( { ignoreUndefinedProperties : true } ) ;
312+ modifyIgnoreUndefinedProperties ( db , previousValue ) ;
304313 return Promise . resolve ( ) ;
305314 } ) ;
306315
0 commit comments