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

#276 implement first tests to fe #283

Merged
merged 8 commits into from
Nov 2, 2023
Merged

Conversation

BelousSofiya
Copy link
Collaborator

Unit tests to CompanyCard, CookieMod, SearchResults, Search components. Just 'first touch'

@BelousSofiya BelousSofiya changed the base branch from master to develop October 27, 2023 13:54
Comment on lines 46 to 47
async () => {
await axios.get.mockResolvedValue({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need async/await here?
I think we can import axios once and then mock it rather than importing it for every test

Copy link
Collaborator Author

@BelousSofiya BelousSofiya Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback. Values, returned by axios.get.mockResolvedValue, are different in those tests. So I can't mock it once
Deleted async/await


afterEach(cleanup);

describe('CookieMod component unit tests', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test cases that verify behavior? I mean hiding a modal when agree was clicked

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback. Done

afterEach(cleanup);

describe('CookieMod component unit tests', () => {
test('renders agry button', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback. Fixed))

expect(axios.get).toBeCalled();
expect(screen.getByText(/назад/i, { exact: false })).toBeInTheDocument();
expect(screen.getByRole('link')).toHaveAttribute('href', '/');
expect(screen.getByText(/3/i, { exact: false })).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test verify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for feedback. By strings:
85 - axios was called from page
86 - button 'назад' exists on the page
87 - button 'назад' binds with link '/' (to the main page)
88 - '3' - number of companies in axios mock request. We see '3' on the page, so the page works correctly

jest.mock('axios');
const axios = require('axios');

() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this wrapper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried 'axios.get = jest.fn().mockResolvedValue({ ...' but it doesn't work(( The only way I've found was this wrapper

@BelousSofiya BelousSofiya merged commit c4d7533 into develop Nov 2, 2023
3 checks passed
@BelousSofiya BelousSofiya deleted the #276ImplementFirstTestsToFE branch November 2, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants