Code
var cartModule = (function() {
var cart = [];
var cart_proxy = new Proxy(cart, {
set: function(target, property, value) {
...
target[property] = value
return true
}
}
return {
toggleItem: function() {
if (value) {
cart_proxy.push(new Item(item_name));
}
}
getItems: function() {
return cart.map( object => object.name );
}
}
})
Spec
describe("when toggleitem is called", function() {
beforeEach(function() {
cartModule.toggleItem("ladder", true)
})
it ('adds item', function() {
expect(cartModule.getItems()).toEqual(["ladder"]);
})
})
Spec fails if the code says cart_proxy.push, but if code says cart.push spec passes. As well in console, I can confirm that cart_proxy.push is working appropriately. Looks like what's failing is something about the use of the Proxy