Browse Source

Fix a potential stub issue

onevcat 1 year ago
parent
commit
98b17d7328
1 changed files with 12 additions and 6 deletions
  1. 12 6
      Tests/KingfisherTests/ImageViewExtensionTests.swift

+ 12 - 6
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -420,13 +420,20 @@ class ImageViewExtensionTests: XCTestCase {
     
     @MainActor func testSettingImageKeepingRespectingPlaceholder() {
         let exp = expectation(description: #function)
-        let url = testURLs[0]
-        stub(url, data: testImageData)
-
+        
         // While current image is nil, set placeholder
-        imageView.kf.setImage(with: url, placeholder: testImage, options: [.keepCurrentImageWhileLoading]) { result in }
-        XCTAssertNotNil(imageView.image)
+        let url = testURLs[0]
+        imageView.kf.setImage(with: url, placeholder: testImage, options: [.keepCurrentImageWhileLoading]) { result in
+            exp.fulfill()
+        }
         XCTAssertEqual(testImage, imageView.image)
+        waitForExpectations(timeout: 3, handler: nil)
+    }
+    
+    @MainActor func testMe() {
+        let exp = expectation(description: #function)
+        let url = testURLs[0]
+        stub(url, data: testImageData)
         
         // While current image is not nil, keep it
         let anotherImage = KFCrossPlatformImage(data: testImageJEPGData)
@@ -435,7 +442,6 @@ class ImageViewExtensionTests: XCTestCase {
             XCTAssertNotEqual(self.imageView.image, anotherImage)
             exp.fulfill()
         }
-        XCTAssertNotNil(imageView.image)
         XCTAssertEqual(anotherImage, imageView.image)
 
         waitForExpectations(timeout: 3, handler: nil)