<button disabled click=”$handleBuyClick(data)”>Buy</button>
it('submits purchase request', () => { controller = new PurchasePage(); // Call the method that handles the "Buy" button click controller.handleBuyClick(data); expect(service).toHaveBeenCalledWith(expectedData); });
it('submits purchase request', () => { // Renders the page with the “Buy” button and its associated code. render(PurchasePage); // Tries to click the button, fails the test, and catches the bug! buttonWithText('Buy').dispatchEvent(new Event(‘click’)); expect(service).toHaveBeenCalledWith(expectedData); });