Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit37e0ce6

Browse files
committed
fix: beef up tests further
1 parent4bd341f commit37e0ce6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎site/src/hooks/useClipboard.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,27 @@ describe.each(secureContextValues)("useClipboard - secure: %j", (isSecure) => {
262262
expect(result.current.error).toBeInstanceOf(Error);
263263
});
264264

265+
it("Clears out existing errors if a new copy operation succeeds",async()=>{
266+
consttext="dummy-text";
267+
const{ result}=renderUseClipboard();
268+
setSimulateFailure(true);
269+
270+
awaitact(()=>result.current.copyToClipboard(text));
271+
expect(result.current.error).toBeInstanceOf(Error);
272+
273+
setSimulateFailure(false);
274+
awaitassertClipboardUpdateLifecycle(result,text);
275+
expect(result.current.error).toBeUndefined();
276+
});
277+
265278
// This check is really important to ensure that it's easy to plop this
266279
// inside of useEffect calls without having to think about dependencies too
267280
// much
268281
it("Ensures that the copyToClipboard function always maintains a stable reference across all re-renders",async()=>{
269282
constinitialOnError=jest.fn();
270283
const{ result, rerender}=renderUseClipboard({
271284
onError:initialOnError,
285+
clearErrorOnSuccess:true,
272286
});
273287
constinitialCopy=result.current.copyToClipboard;
274288

@@ -283,6 +297,11 @@ describe.each(secureContextValues)("useClipboard - secure: %j", (isSecure) => {
283297
expect(result.current.copyToClipboard).toBe(initialCopy);
284298
rerender({onError:initialOnError});
285299

300+
// Re-render with a new clear value then swap back to simplify testing
301+
rerender({onError:initialOnError,clearErrorOnSuccess:false});
302+
expect(result.current.copyToClipboard).toBe(initialCopy);
303+
rerender({onError:initialOnError,clearErrorOnSuccess:true});
304+
286305
// Trigger a failed clipboard interaction
287306
setSimulateFailure(true);
288307
awaitact(()=>result.current.copyToClipboard("dummy-text-2"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp