← Problems
// Users say: "I searched for 'Backpack', clicked Add to cart, and a Water Bottle got added."
export function searchProducts(products, query) {
  return products.filter((product) => product.name.includes(query));
}

export function addToCart(cart, products, productId) {
  const product = products[productId];
  if (!product) return cart;
  const existing = cart.find((line) => line.id === product.id);
  if (existing) {
    existing.quantity += 1;
    return cart;
  }
  return [...cart, { id: product.id, name: product.name, quantity: 1 }];
}

PreviewOpen in new tab ↗Tests

Tests only run when you press ▶ Run tests (next to the Tests heading). Run them again after each change.

Open browser consoleTests

/src/utils/cart.jsJS