@@ -1399,6 +1399,44 @@ describe('withConverter() support', () => {
1399
1399
) ;
1400
1400
} ) ;
1401
1401
} ) ;
1402
+
1403
+ it ( 'allows omitting fields' , async ( ) => {
1404
+ return withTestDoc ( async doc => {
1405
+ const ref = doc . withConverter ( testConverterMerge ) ;
1406
+
1407
+ // Omit outer fields
1408
+ await setDoc (
1409
+ ref ,
1410
+ {
1411
+ outerString : deleteField ( ) ,
1412
+ nested : {
1413
+ innerNested : {
1414
+ innerNestedNum : increment ( 1 )
1415
+ } ,
1416
+ innerArr : arrayUnion ( 2 ) ,
1417
+ timestamp : serverTimestamp ( )
1418
+ }
1419
+ } ,
1420
+ { merge : true }
1421
+ ) ;
1422
+
1423
+ // Omit inner fields
1424
+ await setDoc (
1425
+ ref ,
1426
+ {
1427
+ outerString : deleteField ( ) ,
1428
+ outerArr : [ ] ,
1429
+ nested : {
1430
+ innerNested : {
1431
+ innerNestedNum : increment ( 1 )
1432
+ } ,
1433
+ timestamp : serverTimestamp ( )
1434
+ }
1435
+ } ,
1436
+ { merge : true }
1437
+ ) ;
1438
+ } ) ;
1439
+ } ) ;
1402
1440
} ) ;
1403
1441
1404
1442
describe ( 'WithFieldValue' , ( ) => {
@@ -1421,7 +1459,7 @@ describe('withConverter() support', () => {
1421
1459
} ) ;
1422
1460
} ) ;
1423
1461
1424
- it ( 'requires all fields to be present' , async ( ) => {
1462
+ it ( 'requires all outer fields to be present' , async ( ) => {
1425
1463
return withTestDoc ( async doc => {
1426
1464
const ref = doc . withConverter ( testConverter ) ;
1427
1465
@@ -1440,6 +1478,24 @@ describe('withConverter() support', () => {
1440
1478
} ) ;
1441
1479
} ) ;
1442
1480
1481
+ it ( 'requires all nested fields to be present' , async ( ) => {
1482
+ return withTestDoc ( async doc => {
1483
+ const ref = doc . withConverter ( testConverter ) ;
1484
+
1485
+ await setDoc ( ref , {
1486
+ outerString : 'foo' ,
1487
+ outerArr : [ ] ,
1488
+ // @ts -expect-error
1489
+ nested : {
1490
+ innerNested : {
1491
+ innerNestedNum : increment ( 1 )
1492
+ } ,
1493
+ timestamp : serverTimestamp ( )
1494
+ }
1495
+ } ) ;
1496
+ } ) ;
1497
+ } ) ;
1498
+
1443
1499
it ( 'validates inner and outer fields' , async ( ) => {
1444
1500
return withTestDoc ( async doc => {
1445
1501
const ref = doc . withConverter ( testConverter ) ;
@@ -1497,16 +1553,38 @@ describe('withConverter() support', () => {
1497
1553
} ) ;
1498
1554
} ) ;
1499
1555
1556
+ it ( 'allows certain types but not others (prevent breaking changes)' , ( ) => {
1557
+ const withTryCatch = async ( fn : ( ) => Promise < void > ) : Promise < void > => {
1558
+ try {
1559
+ await fn ( ) ;
1560
+ } catch { }
1561
+ } ;
1562
+
1563
+ return withTestDoc ( async doc => {
1564
+ // @ts -expect-error
1565
+ await withTryCatch ( ( ) => setDoc ( doc , 1 ) ) ;
1566
+ // @ts -expect-error
1567
+ await withTryCatch ( ( ) => setDoc ( doc , 'foo' ) ) ;
1568
+ // @ts -expect-error
1569
+ await withTryCatch ( ( ) => setDoc ( doc , false ) ) ;
1570
+ await withTryCatch ( ( ) => setDoc ( doc , undefined ) ) ;
1571
+ await withTryCatch ( ( ) => setDoc ( doc , null ) ) ;
1572
+ await withTryCatch ( ( ) => setDoc ( doc , [ 0 ] ) ) ;
1573
+ await withTryCatch ( ( ) => setDoc ( doc , new Set < string > ( ) ) ) ;
1574
+ await withTryCatch ( ( ) => setDoc ( doc , new Map < string , number > ( ) ) ) ;
1575
+ } ) ;
1576
+ } ) ;
1577
+
1500
1578
describe ( 'used as a type' , ( ) => {
1501
1579
class ObjectWrapper < T > {
1502
- withFieldValueT ( value : WithFieldValue < T > ) : void {
1503
- // eslint-disable-next-line no-console
1504
- console . log ( value ) ;
1580
+ withFieldValueT ( value : WithFieldValue < T > ) : WithFieldValue < T > {
1581
+ return value ;
1505
1582
}
1506
1583
1507
- withPartialFieldValueT ( value : PartialWithFieldValue < T > ) : void {
1508
- // eslint-disable-next-line no-console
1509
- console . log ( value ) ;
1584
+ withPartialFieldValueT (
1585
+ value : PartialWithFieldValue < T >
1586
+ ) : PartialWithFieldValue < T > {
1587
+ return value ;
1510
1588
}
1511
1589
1512
1590
// Wrapper to avoid having Firebase types in non-Firebase code.
0 commit comments