Skip to content

Commit

Permalink
Fix async await warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravchl committed Apr 26, 2020
1 parent 4bcc778 commit 89b5156
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 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 @@ -98,16 +98,22 @@ describe('Login', () => {
username: 'Carolyne.Carter',
},
});
fireEvent.change(getByLabelText(/username/i), {
target: { value: 'Carolyne.Carter' },
});

fireEvent.change(getByLabelText(/password/i), {
target: { value: 'password' },
});
await act(async () =>
fireEvent.change(getByLabelText(/username/i), {
target: { value: 'Carolyne.Carter' },
})
);

await act(async () =>
fireEvent.change(getByLabelText(/password/i), {
target: { value: 'password' },
})
);

const submit = getByRole('button');
fireEvent.click(submit);
await mockLoginResponse();
await act(async () => fireEvent.click(submit));
await act(async () => mockLoginResponse());
expect(mockLoginResponse).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 89b5156

Please sign in to comment.