Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for pushScopeInProgress #377

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,62 @@ void main() {
);
expect(getIt<TestClass>(instanceName: 'scope3'), isNotNull);
});

group('should remove scope with error during push', () {
test(
'pushNewScope',
() {
final getIt = GetIt.instance;

expect(
() => getIt.pushNewScope(
scopeName: 'scope1',
init: (getIt) {
getIt.registerSingleton(TestClass());
throw Exception('Error during init');
},
),
throwsException,
);

// The scope should not be on the stack and the registered instance
// should be removed.
expect(getIt.hasScope('scope1'), isFalse);
expect(getIt.isRegistered<TestClass>(), isFalse);

// It should be possible to push a new scope.
getIt.pushNewScope(scopeName: 'scope2');

expect(getIt.hasScope('scope2'), isTrue);
},
);

test(
'pushNewScopeAsync',
() async {
final getIt = GetIt.instance;

await expectLater(
() => getIt.pushNewScopeAsync(
scopeName: 'scope1',
init: (getIt) async {
getIt.registerSingleton(TestClass());
throw Exception('Error during init');
},
),
throwsException,
);

// The scope should not be on the stack and the registered instance
// should be removed.
expect(getIt.hasScope('scope1'), isFalse);
expect(getIt.isRegistered<TestClass>(), isFalse);

// It should be possible to push a new scope.
await getIt.pushNewScopeAsync(scopeName: 'scope2');

expect(getIt.hasScope('scope2'), isTrue);
},
);
});
}
Loading