The tea shop's order counter has two bugs, and the starter is the buggy code. It shows Orders: 0 and three buttons. +1 adds one order. +3 adds three at once, for a table of three. +1 later adds one order a second after you click it, for orders phoned in.
The first bug: +3 only adds one. The second: +1 later adds one to the count as it was when you clicked, so anything that happened during that second is lost. Click +1 later, then +3, and a second later the count drops to 1 instead of reaching 4.
Fix both so every click counts. Keep the same text and buttons: +1 adds 1, +3 adds 3, and +1 later adds 1, after 1000 ms, to whatever the count is then. Clicking +1 later twice adds 2.
<p>Orders: 4</p>
<button>+1</button>
<button>+3</button>
<button>+1 later</button>
render(<App />);
expect(screen.getByText("Orders: 0")).toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "+1" }));
expect(screen.getByText("Orders: 1")).toBeInTheDocument();
render(<App />);
await user.click(screen.getByRole("button", { name: "+3" }));
expect(screen.getByText("Orders: 3")).toBeInTheDocument();
render(<App />);
await user.click(screen.getByRole("button", { name: "+3" }));
await user.click(screen.getByRole("button", { name: "+3" }));
expect(screen.getByText("Orders: 6")).toBeInTheDocument();
const clock = useFakeTimers();
render(<App />);
await user.click(screen.getByRole("button", { name: "+1 later" }));
await clock.advance(999);
expect(screen.getByText("Orders: 0")).toBeInTheDocument();
await clock.advance(1);
expect(screen.getByText("Orders: 1")).toBeInTheDocument();
const clock = useFakeTimers();
render(<App />);
await user.click(screen.getByRole("button", { name: "+1 later" }));
await user.click(screen.getByRole("button", { name: "+3" }));
expect(screen.getByText("Orders: 3")).toBeInTheDocument();
await clock.advance(1000);
expect(screen.getByText("Orders: 4")).toBeInTheDocument();
const clock = useFakeTimers();
render(<App />);
await user.click(screen.getByRole("button", { name: "+1 later" }));
await user.click(screen.getByRole("button", { name: "+1" }));
await user.click(screen.getByRole("button", { name: "+1" }));
await clock.advance(1000);
expect(screen.getByText("Orders: 3")).toBeInTheDocument();
const clock = useFakeTimers();
render(<App />);
await user.click(screen.getByRole("button", { name: "+1 later" }));
await user.click(screen.getByRole("button", { name: "+1 later" }));
await clock.advance(1000);
expect(screen.getByText("Orders: 2")).toBeInTheDocument();
Run tests runs every test on your code, here in your browser. The problem is solved when they all pass.
Ctrl + Enter runs the tests (⌘ + Enter on a Mac).
I'm here to help with Fix the order counter. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.