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

Simplify some test type matchers #379

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions test/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void main() {
/// We call [signalReady] before the last has completed
expect(
() => getIt.signalReady(null),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -222,7 +222,7 @@ void main() {
/// We call [signalReady] before the last has completed
expect(
() => getIt.signalReady(null),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});
test('all ready ignoring pending async Singletons', () async {
Expand Down Expand Up @@ -396,7 +396,7 @@ void main() {
instanceName: 'Second Instance',
);

expect(getIt.allReady(), throwsA(isA<StateError>()));
expect(getIt.allReady(), throwsStateError);
});
test('ready manual synchronisation of sequence', () async {
final getIt = GetIt.instance;
Expand Down Expand Up @@ -639,7 +639,7 @@ void main() {
try {
await getIt.allReady(timeout: const Duration(seconds: 1));
} catch (ex) {
expect(ex, const TypeMatcher<WaitingTimeOutException>());
expect(ex, isA<WaitingTimeOutException>());
final timeOut = ex as WaitingTimeOutException;
expect(timeOut.notReadyYet.contains('null : TestClass'), true);
expect(timeOut.notReadyYet.contains('null : TestClass2'), true);
Expand All @@ -666,7 +666,7 @@ void main() {
);

final instance = await getIt.getAsync<TestClass>();
expect(instance, const TypeMatcher<TestClass>());
expect(instance, isA<TestClass>());
});

test('register factory with one Param', () async {
Expand Down Expand Up @@ -765,7 +765,7 @@ void main() {

expect(
() => getIt.getAsync<TestClassParam>(param1: 'abc', param2: '3'),
throwsA(const TypeMatcher<TypeError>()),
throwsA(isA<TypeError>()),
);
});

Expand All @@ -781,7 +781,7 @@ void main() {

expect(
() => getIt.getAsync<TestClassParam>(),
throwsA(const TypeMatcher<TypeError>()),
throwsA(isA<TypeError>()),
);
});

Expand All @@ -795,7 +795,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<AssertionError>()),
throwsA(isA<AssertionError>()),
);
});

Expand All @@ -810,7 +810,7 @@ void main() {
await Future.delayed(const Duration(microseconds: 1));
expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand All @@ -823,7 +823,7 @@ void main() {
);

final instance = await getIt.getAsync<TestClass>();
expect(instance, const TypeMatcher<TestClass>());
expect(instance, isA<TestClass>());
});

test('asyncLazySingleton called with get after wait for ready', () async {
Expand All @@ -838,7 +838,7 @@ void main() {
await getIt.isReady<TestClass>(timeout: const Duration(milliseconds: 20));

final instance2 = getIt.get<TestClass>();
expect(instance2, const TypeMatcher<TestClass>());
expect(instance2, isA<TestClass>());
});

test('isReady called on asyncLazySingleton ', () async {
Expand All @@ -852,7 +852,7 @@ void main() {
await getIt.isReady<TestClass>(timeout: const Duration(milliseconds: 20));

final instance = getIt.get<TestClass>();
expect(instance, const TypeMatcher<TestClass>());
expect(instance, isA<TestClass>());
});

group("dependency", () {
Expand Down
54 changes: 27 additions & 27 deletions test/get_it_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void main() {

expect(
() => getIt.get<TestClassParam>(param1: 'abc', param2: '3'),
throwsA(const TypeMatcher<TypeError>()),
throwsA(isA<TypeError>()),
);
});

Expand All @@ -195,7 +195,7 @@ void main() {

expect(
() => getIt.get<TestClassParam>(param2: '3'),
throwsA(const TypeMatcher<TypeError>()),
throwsA(isA<TypeError>()),
);
});

Expand Down Expand Up @@ -251,7 +251,7 @@ void main() {
await getIt.reset();
expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);

expect(destructorCounter, 1);
Expand All @@ -266,7 +266,7 @@ void main() {
await getIt.reset();
expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);

expect(disposeCounter, 1);
Expand Down Expand Up @@ -343,7 +343,7 @@ void main() {

expect(
() => getIt.get<int>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);

GetIt.I.reset();
Expand Down Expand Up @@ -442,7 +442,7 @@ void main() {

expect(
() => getIt(instanceName: 'not there'),
throwsA(const TypeMatcher<AssertionError>()),
throwsA(isA<AssertionError>()),
);
GetIt.I.reset();
});
Expand Down Expand Up @@ -702,7 +702,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -738,7 +738,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -773,7 +773,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -808,7 +808,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -839,7 +839,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});
test('testing reference counting', () async {
Expand Down Expand Up @@ -880,7 +880,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});
test('testing reference counting - unregister', () async {
Expand Down Expand Up @@ -921,7 +921,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -949,15 +949,15 @@ void main() {

expect(
() => getIt<TestClass>(instanceName: 'instanceName'),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
expect(
getIt<TestClass>(instanceName: 'instanceName2'),
const TypeMatcher<TestClass>(),
isA<TestClass>(),
);
expect(
getIt<TestClass2>(instanceName: 'instanceName'),
const TypeMatcher<TestClass2>(),
isA<TestClass2>(),
);
});

Expand All @@ -984,7 +984,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand All @@ -1011,7 +1011,7 @@ void main() {

expect(
() => getIt.get<TestClass>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand Down Expand Up @@ -1040,7 +1040,7 @@ void main() {

expect(
() => getIt.get<TestClassDisposable>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand All @@ -1061,7 +1061,7 @@ void main() {

expect(
() => getIt<TestClass>(instanceName: 'instanceName'),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});
test('change registration name with type and name', () async {
Expand All @@ -1083,11 +1083,11 @@ void main() {

expect(
() => getIt<TestClass>(instanceName: 'instanceName'),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
expect(
getIt<TestClass>(instanceName: 'instanceName2'),
const TypeMatcher<TestClass>(),
isA<TestClass>(),
);
});

Expand All @@ -1108,7 +1108,7 @@ void main() {
newInstanceName: 'instanceNameExisting',
);
},
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
});

Expand All @@ -1131,11 +1131,11 @@ void main() {

expect(
() => getIt<TestClass>(instanceName: 'instanceName'),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);
expect(
getIt<TestClass>(instanceName: 'instanceName2'),
const TypeMatcher<TestClass>(),
isA<TestClass>(),
);
});

Expand Down Expand Up @@ -1196,7 +1196,7 @@ void main() {

final Injector instance = GetIt.I<Injector>();

expect(instance, const TypeMatcher<Injector>());
expect(instance, isA<Injector>());
});

test('deregister in the same order of registering', () async {
Expand Down Expand Up @@ -1257,7 +1257,7 @@ void main() {

expect(
() => getIt<TestClassDisposableWithDependency>(),
throwsA(const TypeMatcher<StateError>()),
throwsStateError,
);

await getIt.unregister<TestClassDisposable>();
Expand Down
Loading