若想自行建立 Rejected Promise,ECMAScript 提供了三種方式。
Version
macOS Catalina 10.15.5
VS Code 1.46.1
Quokka 1.0.306
ECMAScript 2020
Promise.reject()
let f = x => Promise.reject(x)
f(1) // ?
使用 Promise.reject() static method 將 primitive 包成 Rejected Promise。

Promise Constructor
let f = x => new Promise((_, reject) => reject(x))
f(1) // ?
也可以使用 reject function 傳進 Promise Constructor 建立 Rejected Promise。
Reject function 在第二個 argument,第一個 argument 為 resolve function,因為沒用到故以
_代替

Asynchronous Function
let f = async x => { throw x }
f(1) // ?
最簡單的方式是在 function 前加上 async 成為 asynchronous function,並搭配 throw 產生 Rejected Promise。
由於
throw為 statement,因此一定要加上{}

Conclusion
- 若想快速建立 Promise 供測試,則 asynchronous function 為最簡單方式