Skip to content

Commit a9c12f1

Browse files
timolinsjluxenberg
andcommitted
Add test for race condition
Co-Authored-By: Jared Luxenberg <[email protected]>
1 parent 51d78b5 commit a9c12f1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/toast.test.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import {
33
render,
44
screen,
@@ -319,3 +319,25 @@ test('pause toast', async () => {
319319

320320
expect(toastElement).not.toBeInTheDocument();
321321
});
322+
323+
test('"toast" can be called from useEffect hook', async () => {
324+
const MyComponent = () => {
325+
const [success, setSuccess] = useState(false);
326+
useEffect(() => {
327+
toast.success('Success toast');
328+
setSuccess(true);
329+
}, []);
330+
331+
return success ? <div>MyComponent finished</div> : null;
332+
};
333+
334+
render(
335+
<>
336+
<MyComponent />
337+
<Toaster />
338+
</>
339+
);
340+
341+
await screen.findByText(/MyComponent finished/i);
342+
expect(screen.queryByText(/Success toast/i)).toBeInTheDocument();
343+
});

0 commit comments

Comments
 (0)