var productBasket = function (products) { return { total: function () { if (!products.length) { return 0; } else { return products[0] } } } }; describe('Product basket', function () { describe('#total()', function () { it('returns 0 when basket is empty', function () { expect(productBasket([]).total()).toEqual(0); }); it('returns price of a single product in the basket', function () { expect(productBasket([10]).total()).toEqual(10); }); }) });