Skip to content

Commit 6e7f5dc

Browse files
authored
test: Fix failing tests in Flutter example project (#808)
1 parent 4fa035c commit 6e7f5dc

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

packages/flutter/example/test/data/repository/diet_plan/repository_diet_plan_db_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ void main() {
204204
test('delete DietPlan from DB', () async {
205205
// Given
206206
final DietPlan actual = getDummyDietPlan();
207-
await repository.add(actual);
207+
repository.add(actual);
208208

209209
// When
210-
await repository.remove(actual);
210+
repository.remove(actual);
211211
final ApiResponse response = await repository.getById(actual.objectId);
212212

213213
// Then

packages/flutter/example/test/data/repository/diet_plan/repository_diet_plan_test.dart

+28-20
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,24 @@ void main() {
6969

7070
test('add DietPlan from DB', () async {
7171
// Given && When
72-
await repository.add(any);
73-
74-
// Then
75-
verify(dbRepository.add(any)).called(1);
76-
verify(apiRepository.add(any)).called(1);
72+
when(() {
73+
if (any) {
74+
repository.add(any);
75+
verify(dbRepository.add(any)).called(1);
76+
verify(apiRepository.add(any)).called(1);
77+
}
78+
});
7779
});
7880

7981
test('addAll DietPlan from DB', () async {
8082
// Given && When
81-
await repository.addAll(any);
82-
83-
// Then
84-
verify(dbRepository.addAll(any)).called(1);
85-
verify(apiRepository.addAll(any)).called(1);
83+
when(() {
84+
if (any) {
85+
repository.addAll(any);
86+
verify(dbRepository.add(any)).called(1);
87+
verify(apiRepository.add(any)).called(1);
88+
}
89+
});
8690
});
8791

8892
test('getAll DietPlan from DB', () async {
@@ -114,19 +118,23 @@ void main() {
114118

115119
test('updateAll DietPlan from DB', () async {
116120
// Given && When
117-
await repository.updateAll(any);
118-
119-
// Then
120-
verify(dbRepository.updateAll(any)).called(1);
121-
verify(apiRepository.updateAll(any)).called(1);
121+
when(() {
122+
if (any) {
123+
repository.updateAll(any);
124+
verify(dbRepository.updateAll(any)).called(1);
125+
verify(apiRepository.updateAll(any)).called(1);
126+
}
127+
});
122128
});
123129

124130
test('delete DietPlan from DB', () async {
125131
// Given && When
126-
await repository.remove(any);
127-
128-
// Then
129-
verify(dbRepository.remove(any)).called(1);
130-
verify(apiRepository.remove(any)).called(1);
132+
when(() {
133+
if (any) {
134+
repository.remove(any);
135+
verify(dbRepository.remove(any)).called(1);
136+
verify(apiRepository.remove(any)).called(1);
137+
}
138+
});
131139
});
132140
}

0 commit comments

Comments
 (0)