felangel / felangel/mocktail

Using [thenThrow] and closure in [expect] break [verify] method

Đang mở
#247 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Dart
Star
702
Fork
88
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**Describe the bug**
Using `thenThrow` and closure in `expect` to test throwing will break `verify` method.
Only the first mock function - `verify(() => http.get(any())).called(1);` in this case - is verified.

**To Reproduce**
Run below test

Code

```Dart
// Data Source
class RemoteDataSource {
const RemoteDataSource({
required Client http,
}) : _http = http;

final Client _http;

Future getSomething() async {
final uri = Uri.https('example.com', '/path');
await _http.get(uri);
await _http.post(uri);
await _http.put(uri);
}
}

// Test
class MockHttpClient extends Mock implements Client {}

void main() {
late MockHttpClient http;
late RemoteDataSource remoteDataSource;

setUp(() async {
registerFallbackValue(Uri());
http = MockHttpClient();
remoteDataSource = RemoteDataSource(http: http);
});

group('getSomething', () {
test('post should called once', () {
when(
() => http.get(any()),
).thenAnswer((invocation) async => Response('', 200));
when(
() => http.post(any()),
).thenAnswer((invocation) async => Response('', 200));
when(() => http.put(any())).thenThrow(Exception());

expect(() => remoteDataSource.getSomething(), throwsA(isA()));

verify(() => http.post(any())).called(1);
});
});
}

```

**Expected behavior**
`verify(() => http.post(any())).called(1);` should passed.

**Logs**
```
No matching calls. All calls: MockHttpClient.get(https://example.com/path, {headers: null})
(If you called `verify(...).called(0);`, please instead use `verifyNever(...);`.)
```

**Additional context**
Dart: 3.4.3
Flutter: 3.22.2
mocktail: 1.0.4
http: 1.2.2

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.