From 6b92bd041a0203a4380dff938daa1fda00cd87e3 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Thu, 23 Mar 2017 23:37:06 -0700 Subject: [PATCH] Add emitterEventPromise helper --- spec/async-spec-helpers.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/async-spec-helpers.js b/spec/async-spec-helpers.js index 115f944b5..d00971e2c 100644 --- a/spec/async-spec-helpers.js +++ b/spec/async-spec-helpers.js @@ -1,5 +1,7 @@ /** @babel */ +import until from 'test-until' + export function beforeEach (fn) { global.beforeEach(function () { const result = fn() @@ -60,3 +62,12 @@ function waitsForPromise (fn) { }) }) } + +export function emitterEventPromise (emitter, event, timeout = 5000) { + let called = false + emitter.once(event, () => { + called = true + // disposable.dispose() + }) + return until(`${event} is emitted`, () => called, timeout) +}