@@ -1390,10 +1390,65 @@ test("locked mount cycle", async () => {
1390
1390
} )
1391
1391
1392
1392
test ( "componentWillUnmount" , async ( ) => {
1393
- let unmounted = false
1394
- class Foo extends TestComponent < { } , { text : string } > {
1393
+ let unmountCalled = false
1394
+ let instance : Foo = null as any
1395
+ class Foo extends TestComponent < { } , { } > {
1396
+ constructor ( props : { } ) {
1397
+ super ( props )
1398
+ instance = this
1399
+ }
1400
+
1401
+ componentWillUnmount ( ) : void {
1402
+ unmountCalled = true
1403
+ }
1404
+
1405
+ render ( ) : JSX . Element {
1406
+ return < div />
1407
+ }
1408
+ }
1409
+
1410
+ await renderAndConnect ( < Foo /> , async ( ) => {
1411
+ expect ( unmountCalled ) . toBe ( false )
1412
+ expect ( instance . _unmounted ) . toBe ( false )
1413
+ } )
1414
+
1415
+ // Must wait for close to propagate to server.
1416
+ await new Promise ( resolve => setTimeout ( resolve , 25 ) )
1417
+ expect ( unmountCalled ) . toBe ( true )
1418
+ expect ( instance . _unmounted ) . toBe ( true )
1419
+ } )
1420
+
1421
+ test ( "componentWillUnmount nested error" , async ( ) => {
1422
+ let unmountCalled = false
1423
+ let fooInstance : Foo = null as any
1424
+ class Foo extends TestComponent < { } , { } > {
1425
+ constructor ( props : { } ) {
1426
+ super ( props )
1427
+ fooInstance = this
1428
+ }
1429
+
1430
+ componentWillUnmount ( ) : void {
1431
+ unmountCalled = true
1432
+ }
1433
+
1434
+ render ( ) : JSX . Element {
1435
+ return < Bar />
1436
+ }
1437
+ }
1438
+
1439
+ let barInstance : Bar = null as any
1440
+ class Bar extends TestComponent < { } , { } > {
1441
+ static getUniqueName ( ) : string {
1442
+ return `${ super . getUniqueName ( ) } -bar`
1443
+ }
1444
+
1445
+ constructor ( props : { } ) {
1446
+ super ( props )
1447
+ barInstance = this
1448
+ }
1449
+
1395
1450
componentWillUnmount ( ) : void {
1396
- unmounted = true
1451
+ throw new Error ( "Bar unmount error" )
1397
1452
}
1398
1453
1399
1454
render ( ) : JSX . Element {
@@ -1402,12 +1457,16 @@ test("componentWillUnmount", async () => {
1402
1457
}
1403
1458
1404
1459
await renderAndConnect ( < Foo /> , async ( ) => {
1405
- expect ( unmounted ) . toBe ( false )
1460
+ expect ( unmountCalled ) . toBe ( false )
1461
+ expect ( barInstance . _unmounted ) . toBe ( false )
1462
+ expect ( fooInstance . _unmounted ) . toBe ( false )
1406
1463
} )
1407
1464
1408
1465
// Must wait for close to propagate to server.
1409
1466
await new Promise ( resolve => setTimeout ( resolve , 25 ) )
1410
- expect ( unmounted ) . toBe ( true )
1467
+ expect ( unmountCalled ) . toBe ( true )
1468
+ expect ( barInstance . _unmounted ) . toBe ( true )
1469
+ expect ( fooInstance . _unmounted ) . toBe ( true )
1411
1470
} )
1412
1471
1413
1472
test ( "componentWillReceiveProps" , async ( ) => {
0 commit comments