Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //assume this is a database
- let items = [
- {
- name: "GPU",
- price: 500
- },
- {
- name: "CPU",
- price: 200
- },
- {
- name: "RAM",
- price: 80
- }
- ];
- class Cart {
- constructor(cartItems) {
- this.cartItems = cartItems;
- }
- freeShipping() {
- if (this.getTotal() >= 750) {
- return true;
- } else {
- return false;
- }
- }
- getCart() {
- return this.cartItems;
- }
- getTotal() {
- let total = 0;
- for (let item of this.cartItems) {
- total += item.price;
- }
- return total;
- }
- }
- ///////////////////////////////////////
- let c = new Cart([items[0], items[1]]);
- describe("Cart", function() {
- describe("getCart()", function() {
- it("make sure the variable is instance of cart", function() {
- expect(c).to.be.an.instanceOf(Cart);
- });
- });
- describe("freeShipping()", function() {
- it("free shipping should return true when total is greater than 750", function() {
- fullCart = new Cart(items);
- expect(fullCart.freeShipping()).to.be.true;
- expect(c.freeShipping()).to.be.false;
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement