wechaty-puppet
Version:
Abstract Puppet for Wechaty
51 lines • 1.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tstest_1 = require("tstest");
const rxjs_1 = require("rxjs");
const types_js_1 = require("../src/mods/types.js");
const puppet_test_js_1 = require("./fixtures/puppet-test/puppet-test.js");
/**
* Huan(202111): fromEvent + typed-emitter/rxjs
* @see https://github.com/andywer/typed-emitter/pull/19
*/
const fromEvent = rxjs_1.fromEvent;
// test('Puppet satisfy DOM EventTarget: HasEventTargetAddRemove', async t => {
// const puppet = new PuppetTest()
// // Huan(202110): do not use `tsd` module because the TypeScript version conflict
// // - https://github.com/SamVerschueren/tsd/issues/122
// //
// // expectAssignable<
// // JQueryStyleEventEmitter<
// // any,
// // EventScanPayload | EventLoginPayload
// // >
// // >(puppet)
// const target: JQueryStyleEventEmitter<
// any,
// EventScanPayload | EventLoginPayload
// > = puppet
// void target
// t.pass('expectAssignable match listener argument typings')
// })
(0, tstest_1.test)('RxJS: fromEvent type inference', async (t) => {
const puppet = new puppet_test_js_1.PuppetTest();
/**
* Issue #96: Add Typing support for RxJS fromEvent
* - https://github.com/wechaty/wechaty-puppet/issues/96
*
*/
const event$ = fromEvent(puppet, 'scan');
const typeTest = true;
t.ok(typeTest, 'should be equal type');
const future = (0, rxjs_1.firstValueFrom)(event$);
const payload = {
status: types_js_1.ScanStatus.Unknown,
};
puppet.emit('scan', payload);
const result = await future;
const typeTest2 = true;
t.ok(typeTest2, 'should be equal type');
t.same(result, payload, 'should get scan payload');
});
//# sourceMappingURL=from-event-type.spec.js.map
;