1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
library(testthat)
source("common.R")
describe("2.1. Promise States", {
describe("2.1.1. When pending, a promise:", {
it("2.1.1.1. may transition to either the fulfilled or rejected state.", {
a <- ext_promise()
expect_identical(a$status(), "pending")
a$resolve(0)
expect_identical(a$status(), "fulfilled")
b <- ext_promise()
expect_identical(b$status(), "pending")
squelch_unhandled_promise_error(b$promise)
b$reject("err")
expect_identical(b$status(), "rejected")
})
})
describe("2.1.2. When fulfilled, a promise:", {
it("2.1.2.1. must not transition to any other state.", {
a <- ext_promise()
a$resolve(TRUE)
expect_identical(a$status(), "fulfilled")
a$reject("err")
expect_identical(a$status(), "fulfilled")
})
it("2.1.2.2. must have a value, which must not change.", {
a <- ext_promise()
a$resolve(TRUE)
expect_identical(a$status(), "fulfilled")
a$resolve(FALSE)
expect_identical(extract(a$promise), TRUE)
})
})
describe("2.1.3. When rejected, a promise:", {
it("2.1.3.1. must not transition to any other state.", {
a <- ext_promise()
squelch_unhandled_promise_error(a$promise)
a$reject("err")
expect_identical(a$status(), "rejected")
a$resolve(TRUE)
expect_identical(a$status(), "rejected")
})
it("2.1.3.2. must have a reason, which must not change.", {
a <- ext_promise()
a$reject("err1")
expect_identical(a$status(), "rejected")
a$reject("err2")
expect_error(extract(a$promise), "err1")
})
})
})
|