         XCTAssertEqual(response.cacheType, .memory)
         XCTAssertNotNil(image.image)
     }
+
+    func testRequestCancelledWhenTargetGetsDeallocated() {
+        dataLoader.isSuspended = true
+
+        // Wrap everything in autorelease pool to make sure that imageView
+        // gets deallocated immediately.
+        autoreleasepool {
+            // Given an image view with an associated image task
+            expectNotification(ImagePipelineObserver.didStartTask, object: observer)
+            image.load(pipeline.imagePublisher(with: Test.request))
+            wait()
+
+            // Expect the task to be cancelled automatically
+            expectNotification(ImagePipelineObserver.didCancelTask, object: observer)
+
+            // When the fetch image instance is deallocated
+            image = nil
+        }
+        wait()
+    }
 }


        dataLoader = MockDataLoader()
        imageCache = MockImageCache()
        dataCache = MockDataCache()

        pipeline = ImagePipeline {
            $0.dataLoader = dataLoader
            $0.imageCache = imageCache
            $0.dataCache = dataCache

    var dataLoader: MockDataLoader!
    var imageCache: MockImageCache!
    var dataCache: MockDataCache!
    var observer: ImagePipelineObserver!
    var pipeline: ImagePipeline!
    var image: FetchImage!

