import React, { useState, useEffect, useContext } from 'react';
import {render, act, screen, waitFor, fireEvent} from '@testing-library/react'
import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
import * as fetchUtil from 'api/fetchUtil';
function ProfileView() {
const profile = useContext(ProfileContext);
return (
{ profile.state.profile?.guid }
{ profile.state.profile?.handle }
{ profile.state.profile?.name }
{ profile.state.profile?.description }
{ profile.state.profile?.location }
{ profile.state.profile?.image }
{ profile.state.profile?.revision }
{ profile.state.profile?.seal }
{ profile.state.profile?.version }
{ profile.state.profile?.node }
);
}
function ProfileTestApp() {
return (
)
}
const realFetchWithTimeout = fetchUtil.fetchWithTimeout;
const realFetchWithCustomTimeout = fetchUtil.fetchWithCustomTimeout;
let identity = { };
beforeEach(() => {
const mockFetch = jest.fn().mockImplementation((url, options) => {
if (options.method === 'PUT') {
identity = JSON.parse(options.body);
}
return Promise.resolve({
json: () => Promise.resolve(identity)
});
});
fetchUtil.fetchWithTimeout = mockFetch;
fetchUtil.fetchWithCustomTimeout = mockFetch;
});
afterEach(() => {
fetchUtil.fetchWithTimeout = realFetchWithTimeout;
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
});
test('testing', async () => {
render();
await waitFor(async () => {
expect(screen.getByTestId('name').textContent).toBe("");
});
});