@@ -584,6 +584,32 @@ - (void)testDataTaskWithRequestAndCompletionHandler {
584
584
[instrument deregisterInstrumentors ];
585
585
}
586
586
587
+ /* * Tests that dataTaskWithRequest:completionHandler: for a POST request returns a non-nil object
588
+ * and collects request size. */
589
+ - (void )testDataTaskWithPostRequestAndCompletionHandler {
590
+ FPRNSURLSessionInstrument *instrument = [[FPRNSURLSessionInstrument alloc ] init ];
591
+ [instrument registerInstrumentors ];
592
+ NSURLSession *session = [NSURLSession sharedSession ];
593
+ NSURL *URL = [self .testServer.serverURL URLByAppendingPathComponent: @" test" ];
594
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: URL];
595
+ request.HTTPMethod = @" POST" ;
596
+ request.HTTPBody = [@" sampleData" dataUsingEncoding: NSUTF8StringEncoding];
597
+ XCTestExpectation *expectation = [self expectationWithDescription: @" completionHandler called" ];
598
+
599
+ void (^completionHandler)(NSData *_Nullable, NSURLResponse *_Nullable, NSError *_Nullable) =
600
+ ^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
601
+ [expectation fulfill ];
602
+ };
603
+ NSURLSessionDataTask *dataTask = [session dataTaskWithRequest: request
604
+ completionHandler: completionHandler];
605
+ XCTAssertNotNil (dataTask);
606
+ [dataTask resume ];
607
+ FPRNetworkTrace *trace = [FPRNetworkTrace networkTraceFromObject: dataTask];
608
+ XCTAssertEqual (trace.requestSize , 10 );
609
+ [self waitForExpectationsWithTimeout: 10.0 handler: nil ];
610
+ [instrument deregisterInstrumentors ];
611
+ }
612
+
587
613
/* * Tests that dataTaskWithUrl:completionHandler: returns a non-nil object. */
588
614
- (void )testDataTaskWithUrlAndCompletionHandler {
589
615
FPRNSURLSessionInstrument *instrument = [[FPRNSURLSessionInstrument alloc ] init ];
0 commit comments