Debian Codegraph @

tests/testthat/test-aplus-2-1.R

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