// 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);
});
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.