UNPKG

state-switch

Version:

State Switch is a Change Monitor/Guarder for Async Actions.

38 lines 1.56 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tstest_1 = require("tstest"); const tsd_1 = require("tsd"); const rxjs_1 = require("rxjs"); const mod_js_1 = require("../src/mod.js"); const fromEvent = rxjs_1.fromEvent; (0, tstest_1.test)('RxJS: fromEvent type inference', async (t) => { const state = new mod_js_1.StateSwitch(); const event$ = fromEvent(state, 'active'); (0, tsd_1.expectType)(event$); const future = (0, rxjs_1.firstValueFrom)(event$); state.active('pending'); const result = await future; (0, tsd_1.expectType)(result); t.pass('RxJS typing ok'); t.equal(result, 'pending', 'should get "pending" result'); }); (0, tstest_1.test)('RxJS: fromEvent stream for the second value', async (t) => { const state = new mod_js_1.StateSwitch(); const event$ = fromEvent(state, 'inactive'); state.inactive('pending'); const future = (0, rxjs_1.firstValueFrom)(event$); state.inactive(true); const result = await future; t.equal(result, true, 'should get "true" result'); }); (0, tstest_1.test)('RxJS: fromEvent with StateSwitchInterface', async (t) => { const state = new mod_js_1.StateSwitch(); const event$ = fromEvent(state, 'active'); state.active('pending'); const future = (0, rxjs_1.firstValueFrom)(event$); state.active(true); const result = await future; t.equal(result, true, 'should get "true" result'); }); //# sourceMappingURL=from-event-type.spec.js.map