Skip to content

Commit

Permalink
Increase coverage by checking errors even when save method doesn't …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
caiozullo committed Nov 1, 2023
1 parent 449aa3a commit d16329d
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

0 comments on commit d16329d

Please sign in to comment.