2018-09-02 16:09:49 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2018-09-02 16:09:49 +00:00
|
|
|
import * as smartevent from '../ts/index';
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2018-09-02 16:09:49 +00:00
|
|
|
let myEventEmitter: smartevent.EventEmitter;
|
2017-04-29 19:23:26 +00:00
|
|
|
|
|
|
|
tap.test('should create an emitter ->', async () => {
|
2018-09-02 16:09:49 +00:00
|
|
|
myEventEmitter = new smartevent.EventEmitter();
|
|
|
|
expect(myEventEmitter).to.be.instanceof(smartevent.EventEmitter);
|
|
|
|
});
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2018-12-10 22:54:13 +00:00
|
|
|
tap.test('smartevent.once -> should return a promise', async tools => {
|
2018-12-10 22:41:41 +00:00
|
|
|
const oncePromise = smartevent.once(myEventEmitter, 'customEvent');
|
2018-09-02 16:09:49 +00:00
|
|
|
expect(oncePromise).to.be.instanceof(Promise);
|
2018-12-10 22:41:41 +00:00
|
|
|
expect(oncePromise).to.not.be.rejected;
|
|
|
|
myEventEmitter.emit('customEvent', 'hithere');
|
|
|
|
await expect(oncePromise).to.eventually.be.fulfilled.with.equal('hithere');
|
2018-09-02 16:09:49 +00:00
|
|
|
});
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2018-09-02 16:09:49 +00:00
|
|
|
tap.start();
|