Skip to content

Commit

Permalink
fix: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasprima committed Mar 19, 2024
1 parent ef9fc1c commit ef26e45
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { render, screen, fireEvent, act } from '@testing-library/react';
import TodoList from './features/todos/TodoList';
import React from 'react';
import { store } from './app/store';
import { Provider } from 'react-redux';


test('renders todo list', () => {
render(<TodoList />);
render(
<Provider store={store}>
<TodoList />
</Provider>
);

render(<TodoList />);

const headingElement = screen.getAllByRole('heading', { name: /todo list/i })[0];
const headingElement = screen.getByRole('heading', { name: /todo list/i });
expect(headingElement).toBeInTheDocument();

const inputElement = screen.getByLabelText(/Add to list/i);
Expand All @@ -18,11 +23,15 @@ test('renders todo list', () => {
expect(submitButton).toBeInTheDocument();
});


test('allows user to type in a new todo', () => {
render(<TodoList />);
render(
<Provider store={store}>
<TodoList />
</Provider>);

const inputElement = screen.getByLabelText(/Add to list/i);
fireEvent.change(inputElement, { target: { value: 'New Todo Item' } });
act(() => {
fireEvent.change(inputElement, { target: { value: 'New Todo Item' } });
});
expect(inputElement.value).toBe('New Todo Item');
});
});

0 comments on commit ef26e45

Please sign in to comment.