Skip to content

console.log(localStorage) is returning "null" #87

@Kadessy

Description

@Kadessy

(https://github.com/SuperSimpleDev/javascript-course/assets/92880605/499f5d7c-b17c-4679-a0ad-25c9507c6d20

SCREENSHOT Above

CODE below

import { addToCart, cart } from '../../data/cart.js';

describe('test suite: addToCart', () => {
it('adds and exisiting product to the cart', () => {

});
it('add a new product to the cart', () => {
spyOn(localStorage, 'getItem').and.callFake(() => {
return JSON.stringify({});
});
console.log(localStorage.getItem('cart'));

addToCart('e43638ce-6aa0-4b85-b27f-e1d07eb678c6');
expect(cart.length).toEqual(1);

});
});

From - Lesson 16 (Testing)
Using Jasmine Testing Framework

The above lines of code is supposed to display an empty array in the console since the code is supposed to spyOn locaStorage('getItem')and call fake the cart array, but instead it's returning "null" in the console. I don't know where I went wrong. I need assistance, I have been trying to solve this issue for the past 3 days now.
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions