• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ecamp / hal-json-vuex / 7560312299

17 Jan 2024 06:39PM CUT coverage: 84.708%. Remained the same
7560312299

push

github

web-flow
Update vue monorepo to v2.7.16

159 of 206 branches covered (0.0%)

Branch coverage included in aggregate %.

262 of 291 relevant lines covered (90.03%)

740.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/QueryablePromise.js
1
/**
2
 * This function allow you to modify a JS Promise by adding some status properties.
3
 * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
4
 * But modified according to the specs of promises : https://promisesaplus.com/
5
 */
6
class QueryablePromise {
7
  constructor (promise) {
8
    // Don't modify any promise that has been already modified
9
    if (Symbol.for('isPending') in promise) return promise
1,395✔
10

11
    // Set initial state
12
    let isPending = true
564✔
13
    let isRejected = false
564✔
14
    let isFulfilled = false
564✔
15

16
    // Observe the promise, saving the fulfillment in a closure scope.
17
    const queryablePromise = promise.then(
564✔
18
      function (v) {
19
        isFulfilled = true
504✔
20
        isPending = false
504✔
21
        return v
504✔
22
      },
23
      function (e) {
24
        isRejected = true
60✔
25
        isPending = false
60✔
26
        throw e
60✔
27
      }
28
    )
29

30
    Object.defineProperty(queryablePromise, Symbol.for('isFulfilled'), { get: function () { return isFulfilled } })
564✔
31
    Object.defineProperty(queryablePromise, Symbol.for('isPending'), { get: function () { return isPending } })
564✔
32
    Object.defineProperty(queryablePromise, Symbol.for('isRejected'), { get: function () { return isRejected } })
564✔
33
    Object.defineProperty(queryablePromise, Symbol.for('done'), { get: function () { return !isPending } }) // official terminology would be 'isSettled' or 'isResolved' (https://stackoverflow.com/questions/29268569/what-is-the-correct-terminology-for-javascript-promises)
564✔
34

35
    return queryablePromise
564✔
36
  }
37

38
  /**
39
   * Returns a resolved Promise and immediately mark it as 'done'
40
   */
41
  static resolve (value) {
42
    const promise = Promise.resolve(value)
2,121✔
43

44
    promise[Symbol.for('isFulfilled')] = true
2,121✔
45
    promise[Symbol.for('isPending')] = false
2,121✔
46
    promise[Symbol.for('isRejected')] = false
2,121✔
47
    promise[Symbol.for('done')] = true
2,121✔
48

49
    return promise
2,121✔
50
  }
51
}
52

53
export default QueryablePromise
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc