Last active
August 20, 2020 06:29
-
-
Save Verthon/590ab1fa1ebd00b4d05be46dad4544e8 to your computer and use it in GitHub Desktop.
home test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable @typescript-eslint/camelcase */ | |
import React from 'react'; | |
import { ThemeProvider } from 'styled-components'; | |
import axiosMock from 'axios'; | |
import { render, waitForElement } from 'tests'; | |
import { theme } from 'assets/theme/theme'; | |
import { Home } from './Home'; | |
describe('Homepage', () => { | |
const news = { | |
count: 137, | |
next: 'https://linkshare-api.tshdev.io/resources?page=3&per_page=5', | |
previous: 'https://linkshare-api.tshdev.io/resources?per_page=5', | |
results: [ | |
{ | |
id: 516, | |
url: 'https://linkshare-api.tshdev.io/resources/516', | |
title: 'Shiba inu', | |
description: | |
'The Shiba Inu is a Japanese breed of hunting dog. A small-to-medium breed, it is the smallest of the six original and distinct spitz breeds of dog native to Japan. A small, agile dog that copes very well with mountainous terrain and hiking trails.', | |
resource_url: | |
'https://images.unsplash.com/photo-1552343091-2d9f9bedf206?ixlib=rb-1.2.1&auto=format&fit=crop&w=2850&q=80', | |
thumbnail: | |
'https://linkshare-api.tshdev.io/assets/media/resources/Anonymous/photo-1552343091-2d9f9bedf206_DTQ18PO_CJX5Nos', | |
user: { | |
username: 'Anonymous', | |
id: 76, | |
full_name: 'Anonymous', | |
avatar: 'avatar url', | |
}, | |
tags: ['shiba', 'inu'], | |
user_vote: '11', | |
score: -2, | |
created_at: '2020-04-29T03:15:37.862656Z', | |
}, | |
{ | |
id: 507, | |
url: 'https://linkshare-api.tshdev.io/resources/507', | |
title: 'Emu - Nazywane też: emu zwyczajne', | |
description: | |
'Wysokie, nielotne ptaki o silnie zredukowanych skrzydłach. Przystosowane do wędrówek i biegu nogi są bardzo długie i silnie umięśnione. Stopa dość duża.', | |
resource_url: 'https://www.ekologia.pl/wiedza/zwierzeta/emu-zwyczajne', | |
thumbnail: | |
'https://linkshare-api.tshdev.io/assets/media/resources/demo3/emu-2_bqpo6B0_xm2ACO2_Urt1mdc_sUstwIp.jpg', | |
user: { | |
username: 'demo3', | |
id: 78, | |
full_name: 'demo3', | |
avatar: 'https://avatarfiles.alphacoders.com/132/132335.png', | |
}, | |
tags: ['ptak', 'ptaki', 'emu', 'jajko'], | |
user_vote: '13', | |
score: 2, | |
created_at: '2020-04-16T11:12:30.600452Z', | |
}, | |
], | |
}; | |
// const fetchData = jest.fn(() => Promise.resolve(news)); | |
test('should render the second page', async () => { | |
// const mockFetch = Promise.resolve({ json: () => Promise.resolve(news) }); | |
// const mockedFetch = jest.spyOn(window, 'fetch').mockImplementationOnce(() => mockFetch as never); | |
// await fetchData(); | |
const { container, getByTitle, getByTestId, getByText } = render( | |
<ThemeProvider theme={theme}> | |
<Home /> | |
</ThemeProvider>, | |
); | |
expect(getByTestId('spinner')).toHaveClass('ant-spin'); | |
const resolvedTitle = await waitForElement(() => getByText('Shiba inu')); | |
// expect(await screen.findByText('Shiba inu')).toBeInTheDocument(); | |
// expect(await screen.findByText('Emu - Nazywane też: emu zwyczajne')).toBeInTheDocument(); | |
// fireEvent.click(getByTitle('1')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment