Browse Source

Prevent unfired network stub

onevcat 7 years ago
parent
commit
d3f6656e85

+ 10 - 5
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -229,8 +229,7 @@ class ImageDownloaderTests: XCTestCase {
             result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
-            
-            exp.fulfill()
+            delay(0.1) { exp.fulfill() }
         }
         
         XCTAssertNotNil(task)
@@ -261,7 +260,9 @@ class ImageDownloaderTests: XCTestCase {
         }
 
         task1?.cancel()
-        group.notify(queue: .main, execute: exp.fulfill)
+        group.notify(queue: .main) {
+            delay(0.1) { exp.fulfill() }
+        }
         waitForExpectations(timeout: 1, handler: nil)
     }
     
@@ -291,7 +292,9 @@ class ImageDownloaderTests: XCTestCase {
             _ = stub1.go()
             _ = stub2.go()
         }
-        group.notify(queue: .main, execute: exp.fulfill)
+        group.notify(queue: .main) {
+            delay(0.1) { exp.fulfill() }
+        }
         waitForExpectations(timeout: 5, handler: nil)
     }
     
@@ -330,7 +333,9 @@ class ImageDownloaderTests: XCTestCase {
             group.leave()
         }
         
-        group.notify(queue: .main, execute: exp.fulfill)
+        group.notify(queue: .main) {
+            delay(0.1) { exp.fulfill() }
+        }
         waitForExpectations(timeout: 1, handler: nil)
     }
     

+ 1 - 3
Tests/KingfisherTests/ImagePrefetcherTests.swift

@@ -93,9 +93,7 @@ class ImagePrefetcherTests: XCTestCase {
             XCTAssertEqual(skippedResources.count, 0)
             XCTAssertEqual(failedResources.count, testURLs.count)
             XCTAssertEqual(completedResources.count, 0)
-            delay(0.1) {
-                exp.fulfill()
-            }
+            delay(0.1) { exp.fulfill() }
         }
         
         prefetcher.maxConcurrentDownloads = maxConcurrentCount

+ 8 - 7
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -149,7 +149,7 @@ class ImageViewExtensionTests: XCTestCase {
         {
             result in
             XCTAssertNotNil(result.error)
-            exp.fulfill()
+            delay(0.1) { exp.fulfill() }
         }
 
         XCTAssertNotNil(task)
@@ -187,7 +187,9 @@ class ImageViewExtensionTests: XCTestCase {
         task1?.cancel()
         _ = stub.go()
         
-        group.notify(queue: .main, execute: exp.fulfill)
+        group.notify(queue: .main) {
+            delay(0.1) { exp.fulfill() }
+        }
         waitForExpectations(timeout: 1, handler: nil)
     }
     
@@ -221,7 +223,9 @@ class ImageViewExtensionTests: XCTestCase {
         task3?.cancel()
         _ = stub.go()
         
-        group.notify(queue: .main, execute: exp.fulfill)
+        group.notify(queue: .main) {
+            delay(0.1) { exp.fulfill() }
+        }
         waitForExpectations(timeout: 1, handler: nil)
     }
     
@@ -338,14 +342,11 @@ class ImageViewExtensionTests: XCTestCase {
         imageView.kf.setImage(with: url, progressBlock: { _, _ in XCTFail() }) { result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
+            delay(0.1) { exp.fulfill() }
         }
 
         self.imageView.kf.cancelDownloadTask()
         _ = stub.go()
-        
-        delay(0.1) {
-            exp.fulfill()
-        }
 
         waitForExpectations(timeout: 1, handler: nil)
     }

+ 2 - 6
Tests/KingfisherTests/NSButtonExtensionTests.swift

@@ -115,13 +115,11 @@ class NSButtonExtensionTests: XCTestCase {
         button.kf.setImage(with: url) { result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
+            delay(0.1) { exp.fulfill() }
         }
         
         self.button.kf.cancelImageDownloadTask()
         _ = stub.go()
-        delay(0.1) {
-            exp.fulfill()
-        }
 
         waitForExpectations(timeout: 1, handler: nil)
     }
@@ -134,13 +132,11 @@ class NSButtonExtensionTests: XCTestCase {
         button.kf.setAlternateImage(with: url) { result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
+            delay(0.1) { exp.fulfill() }
         }
         
         self.button.kf.cancelAlternateImageDownloadTask()
         _ = stub.go()
-        delay(0.1) {
-            exp.fulfill()
-        }
         
         waitForExpectations(timeout: 1, handler: nil)
     }

+ 2 - 3
Tests/KingfisherTests/UIButtonExtensionTests.swift

@@ -119,12 +119,11 @@ class UIButtonExtensionTests: XCTestCase {
         button.kf.setImage(with: url, for: .highlighted) { result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
+            delay(0.1) { exp.fulfill() }
         }
         
         self.button.kf.cancelImageDownloadTask()
         _ = stub.go()
-        
-        delay(0.1) { exp.fulfill() }
 
         waitForExpectations(timeout: 1, handler: nil)
     }
@@ -137,11 +136,11 @@ class UIButtonExtensionTests: XCTestCase {
         button.kf.setBackgroundImage(with: url, for: .highlighted) { result in
             XCTAssertNotNil(result.error)
             XCTAssertTrue((result.error as! KingfisherError).isTaskCancelled)
+            delay(0.1) { exp.fulfill() }
         }
         
         self.button.kf.cancelBackgroundImageDownloadTask()
         _ = stub.go()
-        delay(0.1) { exp.fulfill() }
         
         waitForExpectations(timeout: 1, handler: nil)
     }