|
1 | 1 | import {
|
2 |
| - from, |
3 |
| - of, |
4 |
| - defer, |
5 |
| - concat, |
| 2 | + act as componentAct, |
| 3 | + fireEvent, |
| 4 | + render, |
| 5 | + screen, |
| 6 | +} from "@testing-library/react" |
| 7 | +import { act as actHook, renderHook } from "@testing-library/react-hooks" |
| 8 | +import React, { FC, Suspense, useState } from "react" |
| 9 | +import { |
6 | 10 | BehaviorSubject,
|
7 |
| - throwError, |
| 11 | + concat, |
| 12 | + defer, |
| 13 | + from, |
8 | 14 | Observable,
|
| 15 | + of, |
9 | 16 | Subject,
|
| 17 | + throwError, |
10 | 18 | } from "rxjs"
|
11 |
| -import { renderHook, act as actHook } from "@testing-library/react-hooks" |
12 |
| -import { switchMap, delay, take, catchError, map } from "rxjs/operators" |
13 |
| -import { FC, Suspense, useState } from "react" |
14 |
| -import React from "react" |
15 | 19 | import {
|
16 |
| - act as componentAct, |
17 |
| - fireEvent, |
18 |
| - screen, |
19 |
| - render, |
20 |
| -} from "@testing-library/react" |
| 20 | + catchError, |
| 21 | + delay, |
| 22 | + map, |
| 23 | + startWith, |
| 24 | + switchMap, |
| 25 | + take, |
| 26 | +} from "rxjs/operators" |
21 | 27 | import { bind } from "../"
|
22 | 28 | import { TestErrorBoundary } from "../test-helpers/TestErrorBoundary"
|
23 | 29 |
|
@@ -427,6 +433,27 @@ describe("connectFactoryObservable", () => {
|
427 | 433 | unmount()
|
428 | 434 | })
|
429 | 435 |
|
| 436 | + it("supports streams that emit functions", () => { |
| 437 | + const values$ = new Subject<number>() |
| 438 | + |
| 439 | + const [useFunction, function$] = bind(() => |
| 440 | + values$.pipe( |
| 441 | + startWith(0), |
| 442 | + map((value) => () => value), |
| 443 | + ), |
| 444 | + ) |
| 445 | + const subscription = function$().subscribe() |
| 446 | + |
| 447 | + const { result } = renderHook(() => useFunction()) |
| 448 | + |
| 449 | + expect(result.current()).toBe(0) |
| 450 | + |
| 451 | + values$.next(1) |
| 452 | + expect(result.current()).toBe(1) |
| 453 | + |
| 454 | + subscription.unsubscribe() |
| 455 | + }) |
| 456 | + |
430 | 457 | it("if the observable hasn't emitted and a defaultValue is provided, it does not start suspense", () => {
|
431 | 458 | const number$ = new Subject<number>()
|
432 | 459 | const [useNumber] = bind(
|
|
0 commit comments