-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d51c8b
commit 2392a0a
Showing
1 changed file
with
58 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
import type { ReadonlySignal } from "@preact/signals"; | ||
import { createElement, createRef, render, createContext } from "preact"; | ||
import type { ComponentChildren, FunctionComponent } from "preact"; | ||
import { useContext, useRef, useState } from "preact/hooks"; | ||
import { useContext, useEffect, useRef, useState } from "preact/hooks"; | ||
import { setupRerender, act } from "preact/test-utils"; | ||
|
||
const sleep = (ms?: number) => new Promise(r => setTimeout(r, ms)); | ||
|
@@ -829,4 +829,61 @@ describe("@preact/signals", () => { | |
expect(cleanup).to.have.been.calledOnceWith("foo", child); | ||
}); | ||
}); | ||
|
||
// TODO: add test when we upgrade lockfile and Preact to latest | ||
it.skip("Should take hooks-state settling in account", () => { | ||
const renderSpy = sinon.spy(); | ||
const Context = createContext({ | ||
addModal: () => {}, | ||
removeModal: () => {}, | ||
}); | ||
|
||
function ModalProvider(props: any) { | ||
let [modalCount, setModalCount] = useState(0); | ||
renderSpy(modalCount); | ||
let context = { | ||
modalCount, | ||
addModal() { | ||
setModalCount(count => count + 1); | ||
}, | ||
removeModal() { | ||
setModalCount(count => count - 1); | ||
}, | ||
}; | ||
|
||
return ( | ||
// @ts-expect-error | ||
Check failure on line 855 in packages/preact/test/index.test.tsx GitHub Actions / tests
|
||
<Context.Provider value={context}>{props.children}</Context.Provider> | ||
); | ||
} | ||
|
||
function useModal() { | ||
let context = useContext(Context); | ||
useEffect(() => { | ||
context.addModal(); | ||
return () => { | ||
context.removeModal(); | ||
}; | ||
}, [context]); | ||
} | ||
|
||
function Popover() { | ||
useModal(); | ||
return <div>Popover</div>; | ||
} | ||
|
||
function App() { | ||
return ( | ||
<ModalProvider> | ||
<Popover /> | ||
</ModalProvider> | ||
); | ||
} | ||
|
||
act(() => { | ||
render(<App />, scratch); | ||
}); | ||
|
||
expect(renderSpy).to.be.calledTwice; | ||
}); | ||
}); |