Skip to content

Commit

Permalink
Added tests for onSendProgress (#1991)
Browse files Browse the repository at this point in the history
<!-- Write down your pull request descriptions. -->

### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [x] I have added the required tests to prove the fix/feature I'm
adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

### Additional context and info (if any)

<!-- Provide more context and info about the PR. -->
  • Loading branch information
brian030128 authored Oct 13, 2023
1 parent 7170db0 commit 2fbd0a5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dio/test/upload_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ void main() {
},
testOn: 'vm',
);

test('send progress', () async {
final data = ['aaaa', 'hello 😌', 'dio is a dart http client'];
final stream = Stream.fromIterable(data.map((e) => e.codeUnits));
final expanded = data.expand((element) => element.codeUnits);
bool fullFilled = false;
final _ = await dio.put(
'/put',
data: stream,
onSendProgress: (a, b) {
expect(b, expanded.length);
expect(a <= b, isTrue);
if (a == b) {
fullFilled = true;
}
},
options: Options(
contentType: Headers.textPlainContentType,
headers: {
Headers.contentLengthHeader: expanded.length, // set content-length
},
),
);
expect(fullFilled, isTrue);
});
}

class _TestTransformer extends BackgroundTransformer {
Expand Down

0 comments on commit 2fbd0a5

Please sign in to comment.