smartevent/test/test.ts

21 lines
700 B
TypeScript
Raw Normal View History

import { expect, tap } from '@pushrocks/tapbundle';
2017-04-29 19:23:26 +00:00
import * as smartevent from '../ts/index';
2017-04-29 19:23:26 +00:00
let myEventEmitter: smartevent.EventEmitter;
2017-04-29 19:23:26 +00:00
tap.test('should create an emitter ->', async () => {
myEventEmitter = new smartevent.EventEmitter();
expect(myEventEmitter).to.be.instanceof(smartevent.EventEmitter);
});
2017-04-29 19:23:26 +00:00
2018-12-10 22:41:41 +00:00
tap.test('smartevent.once -> should return a promise', async (tools) => {
const oncePromise = smartevent.once(myEventEmitter, 'customEvent');
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');
});
2017-04-29 19:23:26 +00:00
tap.start();