UNPKG

state-switch

Version:

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

36 lines 1.39 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm import { test } from 'tstest'; import { expectType, } from 'tsd'; import { fromEvent as rxFromEvent, firstValueFrom, } from 'rxjs'; import { StateSwitch, } from '../src/mod.js'; const fromEvent = rxFromEvent; test('RxJS: fromEvent type inference', async (t) => { const state = new StateSwitch(); const event$ = fromEvent(state, 'active'); expectType(event$); const future = firstValueFrom(event$); state.active('pending'); const result = await future; expectType(result); t.pass('RxJS typing ok'); t.equal(result, 'pending', 'should get "pending" result'); }); test('RxJS: fromEvent stream for the second value', async (t) => { const state = new StateSwitch(); const event$ = fromEvent(state, 'inactive'); state.inactive('pending'); const future = firstValueFrom(event$); state.inactive(true); const result = await future; t.equal(result, true, 'should get "true" result'); }); test('RxJS: fromEvent with StateSwitchInterface', async (t) => { const state = new StateSwitch(); const event$ = fromEvent(state, 'active'); state.active('pending'); const future = firstValueFrom(event$); state.active(true); const result = await future; t.equal(result, true, 'should get "true" result'); }); //# sourceMappingURL=from-event-type.spec.js.map