Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop wrapping non returning promises in act #215

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, act } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import MinimumDurationLoader from './minimum-duration-loader';

const children = <span data-testid='test-content'>Content</span>;
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('MinimumDurationLoader', () => {
expect(screen.getByTestId('minimum-duration-loader')).toBeInTheDocument();
expect(screen.queryByTestId('test-content')).not.toBeInTheDocument();

act(() => jest.advanceTimersByTime(1000));
jest.advanceTimersByTime(1000);

expect(screen.queryByTestId('minimum-duration-loader')).not.toBeInTheDocument();
expect(screen.getByTestId('test-content')).toBeInTheDocument();
Expand All @@ -46,11 +46,13 @@ describe('MinimumDurationLoader', () => {
test.skip('does not render the content if isLoaded becomes `false` after having been `true`', () => {
const { rerender } = render(<MinimumDurationLoader {...{...props, isLoaded: true}} />)
expect(screen.getByTestId('minimum-duration-loader')).toBeInTheDocument();
act(() => jest.advanceTimersByTime(1000));

jest.advanceTimersByTime(1000);
expect(screen.getByTestId('test-content')).toBeInTheDocument();
rerender(<MinimumDurationLoader {...props } />)
expect(screen.getByTestId('minimum-duration-loader')).toBeInTheDocument();
act(() => jest.advanceTimersByTime(1000));

jest.advanceTimersByTime(1000);
expect(screen.getByTestId('test-content')).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -104,11 +106,11 @@ describe('MinimumDurationLoader', () => {
// Loader should exist
expect(screen.getByTestId('minimum-duration-loader')).toBeInTheDocument();
expect(screen.queryByTestId('test-content')).not.toBeInTheDocument();
act(() => jest.advanceTimersByTime(1000));
jest.advanceTimersByTime(1000);
// Loader should still exist because we exceeded the minimum duration
expect(screen.getByTestId('minimum-duration-loader')).toBeInTheDocument();
expect(screen.queryByTestId('test-content')).not.toBeInTheDocument();
act(() => jest.advanceTimersByTime(4000));
jest.advanceTimersByTime(4000);
// We've exceeded the minimum duration, so the loader should not exist
expect(screen.queryByTestId('minimum-duration-loader')).not.toBeInTheDocument();
expect(screen.getByTestId('test-content')).toBeInTheDocument();
Expand Down Expand Up @@ -198,7 +200,7 @@ describe('MinimumDurationLoader', () => {

expect(mountedCount).toBe(0)

act(() => jest.advanceTimersByTime(60));
jest.advanceTimersByTime(60);
rerender(
<MinimumDurationLoader minDuration={MIN_DURATION} isLoaded={true}>
<Counter />
Expand All @@ -213,7 +215,7 @@ describe('MinimumDurationLoader', () => {
</MinimumDurationLoader>
)

act(() => jest.advanceTimersByTime(60));
jest.advanceTimersByTime(60);

// Mounts since minDuration has passed and isLoaded = true
expect(mountedCount).toBe(1)
Expand All @@ -225,7 +227,7 @@ describe('MinimumDurationLoader', () => {
)

// Confirm that the component has not been mounted again if we move forward in time
act(() => jest.advanceTimersByTime(1));
jest.advanceTimersByTime(1);
expect(mountedCount).toBe(1)
});

Expand All @@ -240,7 +242,7 @@ describe('MinimumDurationLoader', () => {
expect(mountedCount).toBe(0)

// Move forward in time more than minDuration before setting isLoaded = true
act(() => jest.advanceTimersByTime(110));
jest.advanceTimersByTime(110);
rerender(
<MinimumDurationLoader minDuration={MIN_DURATION} isLoaded={true}>
<Counter />
Expand All @@ -251,7 +253,7 @@ describe('MinimumDurationLoader', () => {
expect(mountedCount).toBe(1)

// Confirm that the component has not been mounted again if we move forward in time
act(() => jest.advanceTimersByTime(1));
jest.advanceTimersByTime(1);
rerender(
<MinimumDurationLoader minDuration={MIN_DURATION} isLoaded={true}>
<Counter />
Expand Down
Loading