Last active
January 9, 2016 10:08
-
-
Save ericelliott/b37419f1d885edea39d3 to your computer and use it in GitHub Desktop.
impure addToCart() mutates existing cart. https://jsbin.com/dobefu/edit?html,js,output
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
// impure addToCart mutates existing cart | |
const addToCart = (cart, item, quantity) => { | |
cart.items.push({ | |
item, | |
quantity | |
}); | |
return cart; | |
}; | |
test('addToCart()', assert => { | |
const msg = 'addToCart() should add a new item to the cart.'; | |
const originalCart = { | |
items: [] | |
}; | |
const cart = addToCart( | |
originalCart, | |
{ | |
name: "Digital SLR Camera", | |
price: '1495' | |
}, | |
1 | |
); | |
const expected = 1; // num items in cart | |
const actual = cart.items.length; | |
assert.equal(actual, expected, msg); | |
assert.deepEqual(originalCart, cart, 'mutates original cart.'); | |
assert.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment