Fix tests
This commit is contained in:
parent
f504d17abe
commit
bffe5318a9
5 changed files with 20 additions and 59 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 },
|
||||
];
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@ describe('<EmailVerification />', () => {
|
|||
|
||||
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('<EmailVerification />', () => {
|
|||
|
||||
await waitFor(() => {
|
||||
fireEvent.submit(
|
||||
screen.getByRole('button'), {
|
||||
screen.getByTestId('button'), {
|
||||
preventDefault: () => {},
|
||||
},
|
||||
);
|
||||
|
|
|
@ -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('<SmsVerification />', () => {
|
|||
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('<SmsVerification />', () => {
|
|||
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');
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue