|
2 | 2 | import React, { useEffect } from "rehackt"; |
3 | 3 | import { useRenderGuard } from "../useRenderGuard"; |
4 | 4 | import { render, waitFor } from "@testing-library/react"; |
5 | | -import { withCleanup } from "../../../../testing/internal"; |
6 | 5 |
|
7 | 6 | const UNDEF = {}; |
8 | 7 | const IS_REACT_19 = React.version.startsWith("19"); |
@@ -35,45 +34,3 @@ it("returns a function that returns `false` if called after render", async () => |
35 | 34 | }); |
36 | 35 | expect(result).toBe(false); |
37 | 36 | }); |
38 | | - |
39 | | -function breakReactInternalsTemporarily() { |
40 | | - const R = React as unknown as { |
41 | | - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any; |
42 | | - }; |
43 | | - const orig = R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; |
44 | | - |
45 | | - R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {}; |
46 | | - return withCleanup({}, () => { |
47 | | - R.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = orig; |
48 | | - }); |
49 | | -} |
50 | | - |
51 | | -it("results in false negatives if React internals change", () => { |
52 | | - let result: boolean | typeof UNDEF = UNDEF; |
53 | | - function TestComponent() { |
54 | | - using _ = breakReactInternalsTemporarily(); |
55 | | - const calledDuringRender = useRenderGuard(); |
56 | | - result = calledDuringRender(); |
57 | | - return <>Test</>; |
58 | | - } |
59 | | - render(<TestComponent />); |
60 | | - expect(result).toBe(false); |
61 | | -}); |
62 | | - |
63 | | -it("does not result in false positives if React internals change", async () => { |
64 | | - let result: boolean | typeof UNDEF = UNDEF; |
65 | | - function TestComponent() { |
66 | | - using _ = breakReactInternalsTemporarily(); |
67 | | - const calledDuringRender = useRenderGuard(); |
68 | | - useEffect(() => { |
69 | | - using _ = breakReactInternalsTemporarily(); |
70 | | - result = calledDuringRender(); |
71 | | - }); |
72 | | - return <>Test</>; |
73 | | - } |
74 | | - render(<TestComponent />); |
75 | | - await waitFor(() => { |
76 | | - expect(result).not.toBe(UNDEF); |
77 | | - }); |
78 | | - expect(result).toBe(false); |
79 | | -}); |
0 commit comments