@@ -330,6 +330,7 @@ void main() {
330
330
expect (isShadowed, false );
331
331
expect (shadowingObject, shadowingInstance);
332
332
});
333
+
333
334
test ('popscope' , () async {
334
335
final getIt = GetIt .instance;
335
336
constructorCounter = 0 ;
@@ -362,63 +363,93 @@ void main() {
362
363
);
363
364
});
364
365
365
- test ('popscopeuntil inclusive=true' , () async {
366
+ test ('popScopesTill inclusive=true' , () async {
366
367
final getIt = GetIt .instance;
367
368
constructorCounter = 0 ;
368
369
369
370
getIt.registerSingleton <TestClass >(TestClass ('Basescope' ));
370
371
371
372
getIt.pushNewScope (scopeName: 'Level1' );
372
-
373
- getIt.registerSingleton <TestClass >(TestClass ('2. scope' ));
373
+ getIt.registerSingleton <TestClass >(TestClass ('1. scope' ));
374
374
375
375
getIt.pushNewScope (scopeName: 'Level2' );
376
+ getIt.registerSingleton <TestClass >(TestClass ('2. scope' ));
376
377
378
+ getIt.pushNewScope (scopeName: 'Level3' );
377
379
getIt.registerSingleton <TestClass >(TestClass ('3. scope' ));
380
+ expect (getIt.get <TestClass >().id, '3. scope' );
378
381
379
- final instanceTestClassScope3 = getIt.get <TestClass >();
380
-
381
- expect (instanceTestClassScope3.id, '3. scope' );
382
+ await getIt.popScopesTill ('Level2' );
382
383
383
- await getIt.popScopesTill ('Level1' );
384
-
385
- final instanceTestClassScope1 = getIt.get <TestClass >();
386
-
387
- expect (instanceTestClassScope1.id, 'Basescope' );
384
+ expect (getIt.get <TestClass >().id, '1. scope' );
388
385
expect (
389
386
() => getIt.get <TestClass2 >(),
390
387
throwsStateError,
391
388
);
392
389
});
393
- test ('popscopeuntil inclusive=false' , () async {
390
+
391
+ test ('popScopesTill inclusive=false' , () async {
394
392
final getIt = GetIt .instance;
395
393
constructorCounter = 0 ;
396
394
397
395
getIt.registerSingleton <TestClass >(TestClass ('Basescope' ));
398
396
399
397
getIt.pushNewScope (scopeName: 'Level1' );
400
-
401
- getIt.registerSingleton <TestClass >(TestClass ('2. scope' ));
398
+ getIt.registerSingleton <TestClass >(TestClass ('1. scope' ));
402
399
403
400
getIt.pushNewScope (scopeName: 'Level2' );
401
+ getIt.registerSingleton <TestClass >(TestClass ('2. scope' ));
404
402
403
+ getIt.pushNewScope (scopeName: 'Level3' );
405
404
getIt.registerSingleton <TestClass >(TestClass ('3. scope' ));
405
+ expect (getIt.get <TestClass >().id, '3. scope' );
406
406
407
- final instanceTestClassScope3 = getIt.get <TestClass >();
408
-
409
- expect (instanceTestClassScope3.id, '3. scope' );
410
-
411
- await getIt.popScopesTill ('Level1' , inclusive: false );
407
+ await getIt.popScopesTill ('Level2' , inclusive: false );
412
408
413
- final instanceTestClassScope1 = getIt.get <TestClass >();
414
-
415
- expect (instanceTestClassScope1.id, '2. scope' );
409
+ expect (getIt.get <TestClass >().id, '2. scope' );
416
410
expect (
417
411
() => getIt.get <TestClass2 >(),
418
412
throwsStateError,
419
413
);
420
414
});
421
415
416
+ test ('popScopesTill invalid scope' , () async {
417
+ final getIt = GetIt .instance;
418
+
419
+ getIt.pushNewScope (scopeName: 'Level1' );
420
+ getIt.pushNewScope (scopeName: 'Level2' );
421
+ getIt.pushNewScope (scopeName: 'Level3' );
422
+
423
+ expect (getIt.hasScope ('Level1' ), isTrue);
424
+ expect (getIt.hasScope ('Level2' ), isTrue);
425
+ expect (getIt.hasScope ('Level3' ), isTrue);
426
+
427
+ await getIt.popScopesTill ('Level4' );
428
+
429
+ expect (getIt.hasScope ('Level1' ), isTrue);
430
+ expect (getIt.hasScope ('Level2' ), isTrue);
431
+ expect (getIt.hasScope ('Level3' ), isTrue);
432
+ });
433
+
434
+
435
+ test ('popScopesTill inclusive=false top scope' , () async {
436
+ final getIt = GetIt .instance;
437
+
438
+ getIt.pushNewScope (scopeName: 'Level1' );
439
+ getIt.pushNewScope (scopeName: 'Level2' );
440
+ getIt.pushNewScope (scopeName: 'Level3' );
441
+
442
+ expect (getIt.hasScope ('Level1' ), isTrue);
443
+ expect (getIt.hasScope ('Level2' ), isTrue);
444
+ expect (getIt.hasScope ('Level3' ), isTrue);
445
+
446
+ await getIt.popScopesTill ('Level3' , inclusive: false );
447
+
448
+ expect (getIt.hasScope ('Level1' ), isTrue);
449
+ expect (getIt.hasScope ('Level2' ), isTrue);
450
+ expect (getIt.hasScope ('Level3' ), isTrue);
451
+ });
452
+
422
453
test ('popscope with destructors' , () async {
423
454
final getIt = GetIt .instance;
424
455
@@ -446,6 +477,7 @@ void main() {
446
477
447
478
expect (disposeCounter, 3 );
448
479
});
480
+
449
481
test ('popscope with destructors' , () async {
450
482
final getIt = GetIt .instance;
451
483
0 commit comments