import { Http } from "../../../commons/utils/http"; import { EventType } from "../../../event/core/event"; import { SessionCartRemoveEvent } from "./cart-remove"; beforeEach(() => { const post = jest.fn(); post.mockClear(); (Http as any).post = post; }); test("session cart remove is correctly created and sent to server", async () => { const event = new SessionCartRemoveEvent(); await event.push(); // Should not call server on empty remove event. expect(Http.post).not.toHaveBeenCalled(); event.withProduct("product", 2); expect(event.products).toContainEqual(expect.objectContaining({ product: "product", quantity: 2 })); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ type: EventType.SessionCartRemove, products: expect.any(Array) }), ); });