From d16329d1569f0bd387fbdd260d0cc0a7d9ca5843 Mon Sep 17 00:00:00 2001 From: Caio Zullo Date: Wed, 1 Nov 2023 15:44:36 +0200 Subject: [PATCH] Increase coverage by checking errors even when `save` method doesn't throw an error. If the save method doesn't throw an error, the catch block is never executed, so the error assertion inside the catch block wouldn't execute. To ensure the error assertions always run, we need to move it outside the catch block. --- .../Feed Cache/CacheFeedUseCaseTests.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/EssentialFeed/EssentialFeedTests/Feed Cache/CacheFeedUseCaseTests.swift b/EssentialFeed/EssentialFeedTests/Feed Cache/CacheFeedUseCaseTests.swift index 3b41d8bd..458b37b6 100644 --- a/EssentialFeed/EssentialFeedTests/Feed Cache/CacheFeedUseCaseTests.swift +++ b/EssentialFeed/EssentialFeedTests/Feed Cache/CacheFeedUseCaseTests.swift @@ -75,11 +75,15 @@ class CacheFeedUseCaseTests: XCTestCase { private func expect(_ sut: LocalFeedLoader, toCompleteWithError expectedError: NSError?, when action: () -> Void, file: StaticString = #filePath, line: UInt = #line) { action() + var receivedError: NSError? + do { try sut.save(uniqueImageFeed().models) } catch { - XCTAssertEqual(error as NSError?, expectedError, file: file, line: line) + receivedError = error as NSError? } + + XCTAssertEqual(receivedError, expectedError, file: file, line: line) } }