diff --git a/app/soapbox/__tests__/toast.test.tsx b/app/soapbox/__tests__/toast.test.tsx
index eeb3b926b..4c38755e2 100644
--- a/app/soapbox/__tests__/toast.test.tsx
+++ b/app/soapbox/__tests__/toast.test.tsx
@@ -23,13 +23,7 @@ beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});
-beforeEach(() => {
- jest.useFakeTimers();
-});
-
afterEach(() => {
- jest.runOnlyPendingTimers();
- jest.useRealTimers();
(console.error as any).mockClear();
});
@@ -47,10 +41,6 @@ describe('toasts', () =>{
expect(screen.getByTestId('toast')).toBeInTheDocument();
expect(screen.getByTestId('toast-message')).toHaveTextContent('hello');
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
describe('actionable button', () => {
@@ -62,10 +52,6 @@ describe('toasts', () =>{
});
expect(screen.getByTestId('toast-action')).toHaveTextContent('click me');
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
it('does not render the button', async() => {
@@ -76,10 +62,6 @@ describe('toasts', () =>{
});
expect(screen.queryAllByTestId('toast-action')).toHaveLength(0);
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
@@ -106,10 +88,6 @@ describe('toasts', () =>{
expect(screen.getByTestId('toast')).toBeInTheDocument();
expect(screen.getByTestId('toast-message')).toHaveTextContent('The server is down');
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
@@ -123,10 +101,6 @@ describe('toasts', () =>{
});
expect(screen.queryAllByTestId('toast')).toHaveLength(0);
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
@@ -140,10 +114,6 @@ describe('toasts', () =>{
});
expect(screen.queryAllByTestId('toast')).toHaveLength(0);
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
@@ -160,10 +130,6 @@ describe('toasts', () =>{
expect(screen.getByTestId('toast')).toBeInTheDocument();
expect(screen.getByTestId('toast-message')).toHaveTextContent(message);
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
@@ -179,10 +145,6 @@ describe('toasts', () =>{
expect(screen.getByTestId('toast')).toBeInTheDocument();
expect(screen.getByTestId('toast-message')).toHaveTextContent(message);
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
});
@@ -198,10 +160,6 @@ describe('toasts', () =>{
expect(screen.getByTestId('toast')).toBeInTheDocument();
expect(screen.getByTestId('toast-message')).toHaveTextContent('An unexpected error occurred.');
-
- act(() => {
- jest.advanceTimersByTime(4000);
- });
});
});
});
diff --git a/app/soapbox/actions/__tests__/compose.test.ts b/app/soapbox/actions/__tests__/compose.test.ts
index 1579d63c9..58f83e537 100644
--- a/app/soapbox/actions/__tests__/compose.test.ts
+++ b/app/soapbox/actions/__tests__/compose.test.ts
@@ -46,13 +46,6 @@ describe('uploadCompose()', () => {
const expectedActions = [
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
- {
- type: 'ALERT_SHOW',
- message: 'Image exceeds the current file size limit (10 Bytes)',
- actionLabel: undefined,
- actionLink: undefined,
- severity: 'error',
- },
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
];
@@ -99,13 +92,6 @@ describe('uploadCompose()', () => {
const expectedActions = [
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
- {
- type: 'ALERT_SHOW',
- message: 'Video exceeds the current file size limit (10 Bytes)',
- actionLabel: undefined,
- actionLink: undefined,
- severity: 'error',
- },
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
];
diff --git a/app/soapbox/features/verification/steps/__tests__/email-verification.test.tsx b/app/soapbox/features/verification/steps/__tests__/email-verification.test.tsx
index fc9131b97..d1c71649f 100644
--- a/app/soapbox/features/verification/steps/__tests__/email-verification.test.tsx
+++ b/app/soapbox/features/verification/steps/__tests__/email-verification.test.tsx
@@ -27,13 +27,13 @@ describe('', () => {
await waitFor(() => {
fireEvent.submit(
- screen.getByRole('button'), {
+ screen.getByTestId('button'), {
preventDefault: () => {},
},
);
});
- expect(screen.getByRole('button')).toHaveTextContent('Resend verification email');
+ expect(screen.getByTestId('button')).toHaveTextContent('Resend verification email');
});
});
@@ -54,7 +54,7 @@ describe('', () => {
await waitFor(() => {
fireEvent.submit(
- screen.getByRole('button'), {
+ screen.getByTestId('button'), {
preventDefault: () => {},
},
);
diff --git a/app/soapbox/features/verification/steps/__tests__/sms-verification.test.tsx b/app/soapbox/features/verification/steps/__tests__/sms-verification.test.tsx
index 6cdba4104..097bb2911 100644
--- a/app/soapbox/features/verification/steps/__tests__/sms-verification.test.tsx
+++ b/app/soapbox/features/verification/steps/__tests__/sms-verification.test.tsx
@@ -1,5 +1,7 @@
import userEvent from '@testing-library/user-event';
import React from 'react';
+import { act } from 'react-dom/test-utils';
+import { toast } from 'react-hot-toast';
import { __stub } from 'soapbox/api';
import { fireEvent, render, screen, waitFor } from 'soapbox/jest/test-helpers';
@@ -38,6 +40,10 @@ describe('', () => {
expect(screen.getByRole('heading')).toHaveTextContent('Verification code');
expect(screen.getByTestId('toast')).toHaveTextContent('A verification code has been sent to your phone number.');
+ act(() => {
+ toast.remove();
+ });
+
await userEvent.type(screen.getByLabelText('Please enter verification code. Digit 1'), '1');
await userEvent.type(screen.getByLabelText('Digit 2'), '2');
await userEvent.type(screen.getByLabelText('Digit 3'), '3');
@@ -65,6 +71,10 @@ describe('', () => {
expect(screen.getByRole('heading')).toHaveTextContent('Verification code');
expect(screen.getByTestId('toast')).toHaveTextContent('A verification code has been sent to your phone number.');
+ act(() => {
+ toast.remove();
+ });
+
await userEvent.type(screen.getByLabelText('Please enter verification code. Digit 1'), '1');
await userEvent.type(screen.getByLabelText('Digit 2'), '2');
await userEvent.type(screen.getByLabelText('Digit 3'), '3');
diff --git a/app/soapbox/jest/test-setup.ts b/app/soapbox/jest/test-setup.ts
index 0be183998..02b746f18 100644
--- a/app/soapbox/jest/test-setup.ts
+++ b/app/soapbox/jest/test-setup.ts
@@ -1,5 +1,7 @@
'use strict';
+import { toast } from 'react-hot-toast';
+
import { __clear as clearApiMocks } from '../api/__mocks__';
// API mocking
@@ -16,6 +18,11 @@ require('fake-indexeddb/auto');
// Mock external dependencies
jest.mock('uuid', () => ({ v4: jest.fn(() => '1') }));
+// Clear toasts after each test.
+afterEach(() => {
+ toast.remove();
+});
+
const intersectionObserverMock = () => ({ observe: () => null, disconnect: () => null });
window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);