Last active
August 29, 2015 14:06
-
-
Save gajus/2a7fd107f897213aee67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment