-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from venkata-reddy-dev/master
feat: skipDoubleRegistration configuration
- Loading branch information
Showing
5 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test(' Throws ArgumentError ', () async { | ||
final getIt = GetIt.instance; | ||
getIt.allowReassignment = false; | ||
getIt.skipDoubleRegistration = false; | ||
getIt.reset(); | ||
getIt.registerSingleton<DataStore>(MockDataStore()); | ||
|
||
expect( | ||
() => getIt.registerSingleton<DataStore>(RemoteDataStore()), | ||
throwsArgumentError, | ||
); | ||
}); | ||
|
||
test(' replaces dependency safely ', () async { | ||
final getIt = GetIt.instance; | ||
getIt.reset(); | ||
getIt.allowReassignment = true; | ||
getIt.skipDoubleRegistration = false; | ||
getIt.registerSingleton<DataStore>(MockDataStore()); | ||
getIt.registerSingleton<DataStore>(RemoteDataStore()); | ||
|
||
expect(getIt<DataStore>(), isA<RemoteDataStore>()); | ||
}); | ||
|
||
test(' Ignores Double registration error ', () async { | ||
final getIt = GetIt.instance; | ||
getIt.reset(); | ||
getIt.allowReassignment = false; | ||
getIt.skipDoubleRegistration = true; | ||
getIt.registerSingleton<DataStore>(MockDataStore()); | ||
final remoteDataStore = RemoteDataStore(); | ||
getIt.registerSingleton<DataStore>(remoteDataStore); | ||
|
||
expect(getIt<DataStore>(), isA<MockDataStore>()); | ||
}); | ||
|
||
test(' does not care about [skipDoubleRegistration] varibale ', () async { | ||
final getIt = GetIt.instance; | ||
getIt.reset(); | ||
getIt.allowReassignment = true; | ||
getIt.skipDoubleRegistration = true; | ||
getIt.registerSingleton<DataStore>(MockDataStore()); | ||
getIt.registerSingleton<DataStore>(RemoteDataStore()); | ||
|
||
expect(getIt<DataStore>(), isA<RemoteDataStore>()); | ||
}); | ||
} | ||
|
||
abstract class DataStore {} | ||
|
||
class RemoteDataStore implements DataStore {} | ||
|
||
class MockDataStore implements DataStore {} |