Skip to content

Commit

Permalink
Intento arreglo de tests 9
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289039 committed Mar 14, 2024
1 parent 6fe0e7d commit dd4ca76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
18 changes: 11 additions & 7 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe('Login component', () => {

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/login').reply(200, { createdAt: '2024-01-01T12:34:56Z' });
expect(sendLogin.mock.calls[0][0]).toBe(true);
expect(sendUsername.mock.calls[0]).toBe(usernameInput);


// Simulate user input
await act(async () => {
Expand All @@ -36,6 +35,8 @@ describe('Login component', () => {
// Verify that the user information is displayed
expect(screen.getByText(/Hello testUser!/i)).toBeInTheDocument();
expect(screen.getByText(/Your account was created on 1\/1\/2024/i)).toBeInTheDocument();
expect(sendLogin.mock.calls[0][0]).toBe(true);
expect(sendUsername.mock.calls[0]).toBe(usernameInput);
});

it('should handle error when logging in', async () => {
Expand All @@ -50,8 +51,7 @@ describe('Login component', () => {
// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/login').reply(401, { error: 'Unauthorized' });

expect(sendLogin.mock.calls[0][0]).toBe(false);
expect(sendUsername.mock.calls[0]).toBe(usernameInput);

// Simulate user input
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
Expand All @@ -67,5 +67,7 @@ describe('Login component', () => {
// Verify that the user information is not displayed
expect(screen.queryByText(/Hello testUser!/i)).toBeNull();
expect(screen.queryByText(/Your account was created on/i)).toBeNull();
expect(sendLogin.mock.calls[0][0]).toBe(false);
expect(sendUsername.mock.calls[0]).toBe(usernameInput);
});
});

0 comments on commit dd4ca76

Please sign in to comment.