// The hash (#) and dot (.) symbols are a convention to mark if a method // is called on an individual object or on the prototype. ".create" is // called on the Cart prototype. #add are called on the derived objects. describe('Cart', function () { var cart; beforeEach(function () { cart = Cart.create(); }); describe('.create', function () { it('must create a cart that contains 0 products', function () { var cart = Cart.create(); expect(cart.numProducts()).toEqual(0); }); }); describe('#add', function () { it('must add a product to the cart', function () { var product = {}; cart.add(product); expect(cart.doesContain(product)).toBeTruthy(); }); }); describe('#doesContain', function () { it('must return false for a product that is not contained', function () { var product = {}; cart.add({}); expect(cart.doesContain(product)).toBeFalsy(); }); }); describe('#grossPriceSum', function () { it('must return 0 for an empty cart', function () { expect(cart.grossPriceSum()).toBe(0); }); it('must return price for a single product in the cart', function () { var product; product = { grossPrice: function () { return 0; } }; spyOn(product, 'grossPrice').and.returnValue(10); cart.add(product); expect(cart.grossPriceSum()).toBe(10); }); it('must return price for two products in the cart', function () { cart.add({grossPrice: function () { return 10; }}); cart.add({grossPrice: function () { return 20; }}); expect(cart.grossPriceSum()).toBe(30); }); }); });