- 安装promises-aplus-tests
npm install promises-aplus-tests -D
- 手写代码中加入 deferred
// my-promise.js
MyPromise {
......
}
MyPromise.deferred = function () {
var result = {};
result.promise = new MyPromise(function (resolve, reject) {
result.resolve = resolve;
result.reject = reject;
});
return result;
}
module.exports = MyPromise;
- 配置启动命令
// package.json
"scripts": {
"test": "promises-aplus-tests ./my-promise/index.js"
}
- 启动
npm run test