Skip to content

Commit

Permalink
🦺 fail to silence wrap-in-act warning in Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
json2d committed Mar 21, 2024
1 parent c5118e5 commit 135d20a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 53 deletions.
30 changes: 0 additions & 30 deletions stories/DemoHelloer.stories.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions stories/components/DemoHelloer.tsx

This file was deleted.

39 changes: 28 additions & 11 deletions test/Suspension.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { Suspense } from 'react';
* render: lets us render the component (like how React would)
* screen: Your utility for finding elements the same way the user does
**/
import { render, screen, waitFor } from '@testing-library/react';
import { act, render, screen, waitFor } from '@testing-library/react';

import '@testing-library/jest-dom';

Expand Down Expand Up @@ -37,8 +37,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);

act(() => {
render(<App />);
});
expect(screen.queryByRole('heading')).not.toBeNull();
});
});
Expand All @@ -50,7 +51,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});

expect(screen.queryByRole('alert')).not.toBeNull();
expect(screen.queryByRole('heading')).toBeNull();
Expand All @@ -65,7 +68,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});
expect(screen.queryByRole('alert')).not.toBeNull();
expect(screen.queryByRole('heading')).toBeNull();
expect(screen.queryByRole('note')).toBeNull();
Expand All @@ -83,7 +88,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});
expect(screen.queryByRole('alert')).not.toBeNull();
expect(screen.queryByRole('heading')).toBeNull();

Expand All @@ -99,7 +106,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});
expect(screen.queryByRole('heading')).not.toBeNull();
expect(screen.queryByRole('alert')).toBeNull();
expect(mockDeconstructiveEffect.mock.calls.length).toBe(1);
Expand All @@ -121,7 +130,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});

await waitFor(() => screen.getByRole('alert'));
expect(screen.queryByRole('heading')).toBeNull();
Expand All @@ -145,7 +156,9 @@ describe('given an `App` component that renders a bound `Suspension` component',
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});

await waitFor(() => screen.getByRole('alert'));
expect(screen.queryByRole('heading')).toBeNull();
Expand All @@ -165,7 +178,9 @@ describe('given an `App` component that renders a bound `Suspension` component w
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});

expect(screen.queryByRole('alert')).not.toBeNull();
expect(screen.queryByRole('heading')).toBeNull();
Expand All @@ -180,7 +195,9 @@ describe('given an `App` component that renders a bound `Suspension` component w
</Suspense>
);

render(<App />);
act(() => {
render(<App />);
});

expect(screen.queryByRole('heading')).not.toBeNull();
expect(screen.queryByRole('alert')).toBeNull();
Expand Down

0 comments on commit 135d20a

Please sign in to comment.