/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/server/src/observable/behaviorSubject.test.ts
35 строк
783 B
Alex / KATT
feat(subscriptions): connection state (#6084)
21 окт 2024, 01:15
Не верифицирован
21 окт 2024, 01:15
f73cd3f
Код
Авторство
О чём код?
import { behaviorSubject } from './behaviorSubject'; test('behaviorSubject', () => { const value = behaviorSubject(1); expect(value.get()).toBe(1); expectTypeOf(value.get()).toBeNumber(); const onNext1 = vi.fn(); const onNext2 = vi.fn(); const sub = value.subscribe({ next: onNext1, }); expect(onNext1).toHaveBeenCalledWith(1); value.next(2); expect(onNext1).toHaveBeenCalledWith(2); const sub2 = value.subscribe({ next: onNext2, }); expect(onNext1).toHaveBeenCalledWith(2); sub.unsubscribe(); value.next(3); expect(onNext1).not.toHaveBeenCalledWith(3); expect(onNext2).toHaveBeenCalledWith(3); sub2.unsubscribe(); value.next(4); expect(onNext2).not.toHaveBeenCalledWith(4); expect(onNext1).not.toHaveBeenCalledWith(4); });