             let result = Result<String> { throw expectedError }
             let promise = Promise(result: result)
 
-            var completionWasRun = false
-            promise.call { result in
-                completionWasRun = true
-                TestHelpers.expectFailure(expectedError, result: result)
-            }
-
-            XCTAssertTrue(completionWasRun, "Expected the completion block to be called immediately.")
+            let completionCalled = expectationWithDescription("Completion was called")
+            promise.call { result in
+                completionCalled.fulfill()
+                TestHelpers.expectFailure(expectedError, result: result)
+            }
+
+            waitForExpectationsWithTimeout(1.0, handler: nil)
         }
     }
 

            let initialPromise = Promise(value: 3)
            let expectedError = TestHelpers.uniqueError()

            var transformWasRun = false
            let promise = initialPromise.tryMap { value -> Int in
                transformWasRun = true
                throw expectedError
            }

            var completionWasRun = false
            promise.call { result in
                completionWasRun = true
                TestHelpers.expectFailure(expectedError, result: result)
            }

            XCTAssertTrue(transformWasRun, "Expected the transform closure to be called immediately.")
            XCTAssertTrue(completionWasRun, "Expected the completion block to be called immediately.")
        }

        // Try-map failure to failure

    func testInDispatchGroup() {
        let expectedValue = 3

        let taskCalled = expectationWithDescription("Task was called")
        let promise = Promise<Int> { fulfill in
            taskCalled.fulfill()

            XCTAssertTrue(NSThread.isMainThread(), "Expected the task to run on the main thread.")

