Files
Jot/Carthage/Checkouts/PromiseKit/Tests/A+/2.2.7.swift
James Griffin be7b6b5881 Add PromiseKit dependency
- Added PromiseKit dependency
2018-11-15 22:12:39 -04:00

34 lines
1.2 KiB
Swift

import PromiseKit
import XCTest
class Test227: XCTestCase {
func test() {
describe("2.2.7: `then` must return a promise: `promise2 = promise1.then(onFulfilled, onRejected)") {
describe("2.2.7.2: If either `onFulfilled` or `onRejected` throws an exception `e`, `promise2` must be rejected with `e` as the reason.") {
testFulfilled { promise1, expectation, _ in
let sentinel = arc4random()
let promise2 = promise1.done { _ in throw Error.sentinel(sentinel) }
promise2.catch {
if case Error.sentinel(let x) = $0, x == sentinel {
expectation.fulfill()
}
}
}
testRejected { promise1, expectation, _ in
let sentinel = arc4random()
let promise2 = promise1.recover { _ -> Promise<UInt32> in throw Error.sentinel(sentinel) }
promise2.catch { error in
if case Error.sentinel(let x) = error, x == sentinel {
expectation.fulfill()
}
}
}
}
}
}
}