8
NodeJS UnhandledPromiseRejection警告
因此,我正在测试依赖于事件发射器的组件。为此,我想出了将Promises与Mocha + Chai结合使用的解决方案: it('should transition with the correct event', (done) => { const cFSM = new CharacterFSM({}, emitter, transitions); let timeout = null; let resolved = false; new Promise((resolve, reject) => { emitter.once('action', resolve); emitter.emit('done', {}); timeout = setTimeout(() => { if (!resolved) { reject('Timedout!'); } clearTimeout(timeout); }, 100); }).then((state) …