Skip to content

[WIP] PR to fix the react testing library console warnings in the PR for issue-101 #111

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions src/components/Auth/AuthForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { BrowserRouter } from 'react-router-dom';
import AuthForm from './AuthForm';
Expand Down Expand Up @@ -40,46 +40,48 @@ describe('AuthForm', () => {
});

describe('Signup', () => {
it('Register a new user on the signup form', async () => {
const { getByText, getByLabelText } = render(
<BrowserRouter>
<SignUpForm />
</BrowserRouter>
);
fit('Register a new user on the signup form', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

fit? is this intended? :D

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that was so I could test a single test at a time :) I pushed up a commit... one sec!

Copy link
Member Author

Choose a reason for hiding this comment

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

I applied bf9c00b based on @gauravchl's suggestion in 89b5156, but the interesting thing here is that if I run each test using fit individually, the tests pass without those warnings.

But if I run npm run test with that commit in place, I still see:
image

Not sure if there is something I'm obvious I missed, but tldr I'm very surprised to still see that error if I don't run each test individually...

Copy link
Member Author

Choose a reason for hiding this comment

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

I recorded a quick screenrecording about the problem: https://gitduck.com/watch/5ea551ce1f9488f393e05e1a

await act(async () => {
const { getByText, getByLabelText } = render(
<BrowserRouter>
<SignUpForm />
</BrowserRouter>
);

const mockRegisterResponse = jest.fn().mockResolvedValue({
data: {
username: 'Carolyne.Carter',
token:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IkNhcm9seW5lLkNhcnRlciIsImlhdCI6MTU4NDMzODQ4NiwiZXhwIjoxNTg0MzQyMDg2LCJ1c2VyX2lkIjo4MCwib3JpZ19pYXQiOjE1ODQzMzg0ODZ9.saO6OCOKV1uwHjTbM-iDGmhbkMNCnzrGFj4TBYnTv2E',
first_name: 'Carolyne',
last_name: 'Carter',
email: '[email protected]',
},
});
const mockRegisterResponse = jest.fn().mockResolvedValue({
data: {
username: 'Carolyne.Carter',
token:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IkNhcm9seW5lLkNhcnRlciIsImlhdCI6MTU4NDMzODQ4NiwiZXhwIjoxNTg0MzQyMDg2LCJ1c2VyX2lkIjo4MCwib3JpZ19pYXQiOjE1ODQzMzg0ODZ9.saO6OCOKV1uwHjTbM-iDGmhbkMNCnzrGFj4TBYnTv2E',
first_name: 'Carolyne',
last_name: 'Carter',
email: '[email protected]',
},
});

fireEvent.change(getByLabelText(/username/i), {
target: { value: 'Carolyne.Carter' },
});
fireEvent.change(getByLabelText(/username/i), {
target: { value: 'Carolyne.Carter' },
});

fireEvent.change(getByLabelText(/password/i), {
target: { value: 'password' },
});
fireEvent.change(getByLabelText(/email/i), {
target: { value: '[email protected]' },
});
fireEvent.change(getByLabelText(/first name/i), {
target: { value: 'Carolyne' },
});
fireEvent.change(getByLabelText(/last name/i), {
target: { value: 'Carter' },
});
const submit = getByText('Sign Up');
fireEvent.click(submit);
fireEvent.change(getByLabelText(/password/i), {
target: { value: 'password' },
});
fireEvent.change(getByLabelText(/email/i), {
target: { value: '[email protected]' },
});
fireEvent.change(getByLabelText(/first name/i), {
target: { value: 'Carolyne' },
});
fireEvent.change(getByLabelText(/last name/i), {
target: { value: 'Carter' },
});
const submit = getByText('Sign Up');
fireEvent.click(submit);

await mockRegisterResponse();
await mockRegisterResponse();

expect(mockRegisterResponse).toHaveBeenCalledTimes(1);
expect(mockRegisterResponse).toHaveBeenCalledTimes(1);
});
});
});

Expand Down