Skip to content

Commit

Permalink
Implement testKeepingFulfill
Browse files Browse the repository at this point in the history
  • Loading branch information
koher committed Dec 27, 2017
1 parent 4af4397 commit 7964e06
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Tests/PromiseKTests/PromiseKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,46 @@ class PromiseKTests: XCTestCase {
}
}

func testKeepingFulfill() {
do {
var fulfill: ((Int) -> ())!
let a = Promise<Int> {
fulfill = $0
}
fulfill(42)
XCTAssertEqual(a.sync(), 42)
}

do {
var fulfill: ((@escaping () throws -> Int) -> ())!
let a = Promise<() throws -> Int> {
fulfill = $0
}
fulfill { 42 }
XCTAssertEqual(try! a.sync()(), 42)
}

do {
let queue = DispatchQueue(label: "foo", attributes: [])

var fulfill: ((@escaping () throws -> Int) -> ())!
let a = Promise<() throws -> Int> {
fulfill = $0
}

let expectation = self.expectation(description: "testKeepingFulfill")

queue.asyncAfter(deadline: .now() + 0.01) {
fulfill { 42 }
expectation.fulfill()
}

waitForExpectations(timeout: 3.0, handler: nil)

XCTAssertEqual(try! a.sync()(), 42)
}
}

func testSample() {
do {
// `flatMap` is equivalent to `then` of JavaScript's `Promise`
Expand Down

0 comments on commit 7964e06

Please sign in to comment.