diff --git a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift index 5b74017d..79484674 100644 --- a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift +++ b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift @@ -29,6 +29,7 @@ class GlobalErrorResponseHandlerTests: XCTestCase { expectation.fulfill() } handler.reportGlobalError(error.typeErased) + wait(for: [expectation], timeout: 1) } func testGlobalHandlerReportsRouteError() { @@ -46,27 +47,39 @@ class GlobalErrorResponseHandlerTests: XCTestCase { expectation.fulfill() } handler.reportGlobalError(error.typeErased) + wait(for: [expectation], timeout: 1) } func testDeregisterGlobalHandler() { + let expectation = XCTestExpectation(description: "Callback is called") + expectation.isInverted = true let key = handler.registerGlobalErrorHandler { error in + expectation.fulfill() XCTFail("Should not be called") } handler.deregisterGlobalErrorHandler(key: key) let error = CallError.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def") handler.reportGlobalError(error.typeErased) + + wait(for: [expectation], timeout: 1) } func testDeregisterAllGlobalHandlers() { + let expectation = XCTestExpectation(description: "Callback is called") + expectation.isInverted = true _ = handler.registerGlobalErrorHandler { error in + expectation.fulfill() XCTFail("Should not be called") } _ = handler.registerGlobalErrorHandler { error in + expectation.fulfill() XCTFail("Should not be called") } handler.deregisterAllGlobalErrorHandlers() let error = CallError.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def") handler.reportGlobalError(error.typeErased) + + wait(for: [expectation], timeout: 1) } } @@ -135,6 +148,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } func testDownloadRequestGlobalErrorHandler() { @@ -165,6 +179,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } func testUploadRequestGlobalErrorHandler() { @@ -199,5 +214,6 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } }