We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 51d78b5 commit a9c12f1Copy full SHA for a9c12f1
test/toast.test.tsx
@@ -1,4 +1,4 @@
1
-import React from 'react';
+import React, { useEffect, useState } from 'react';
2
import {
3
render,
4
screen,
@@ -319,3 +319,25 @@ test('pause toast', async () => {
319
320
expect(toastElement).not.toBeInTheDocument();
321
});
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