forked from mobxjs/mobx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for mobxjs#3776 (mobxjs#3787)
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/mobx-react/__tests__/timerBasedFinalizationRegistry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import "./utils/killFinalizationRegistry" | ||
import { cleanup, render, act } from "@testing-library/react" | ||
import * as mobx from "mobx" | ||
import * as React from "react" | ||
import { observer } from "../src" | ||
import { clearTimers } from "mobx-react-lite" | ||
|
||
expect(globalThis.FinalizationRegistry).toBeUndefined() | ||
|
||
afterEach(cleanup) | ||
|
||
test("should unregister from FinalizationRegistry once commited #3776", async () => { | ||
const o = mobx.observable({ x: 0 }) | ||
|
||
@observer | ||
class TestCmp extends React.Component<any> { | ||
render() { | ||
return o.x | ||
} | ||
} | ||
|
||
const { unmount, container } = render(<TestCmp />) | ||
|
||
expect(container).toHaveTextContent("0") | ||
|
||
// If not unregistered, clearTimes disposes reaction | ||
clearTimers() | ||
|
||
act(() => { | ||
o.x++ | ||
}) | ||
|
||
expect(container).toHaveTextContent("1") | ||
|
||
unmount() | ||
}) |
4 changes: 4 additions & 0 deletions
4
packages/mobx-react/__tests__/utils/killFinalizationRegistry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// We want to be able to test reaction cleanup code that based on FinalizationRegistry & timers on the same run | ||
// For that we import this file on the beginning on the timer based test to the feature detection will pick the timers impl | ||
// @ts-ignore | ||
global.FinalizationRegistry = undefined |