Complete the code to clear all local storage data before each test.
beforeEach(() => {
cy.[1]();
});In Cypress, cy.clearLocalStorage() is the correct command to clear all local storage data. It is a function and must be called with parentheses.
Complete the code to set a local storage item with key 'token' and value 'abc123'.
cy.window().then((win) => {
win.localStorage.[1]('token', 'abc123');
});getItem instead of setItem.clear which removes all items.The setItem method stores a key-value pair in local storage. Here, it sets the key 'token' with the value 'abc123'.
Fix the error in the code to correctly assert that local storage has a key 'user' with value 'admin'.
cy.window().then((win) => {
expect(win.localStorage.[1]('user')).to.equal('admin');
});setItem which sets a value instead of getting it.removeItem or clear which do not return values.The getItem method retrieves the value for a given key from local storage. To check the value of 'user', we must use getItem('user').
Fill both blanks to create a test that sets a local storage item and then verifies it.
cy.window().then((win) => {
win.localStorage.[1]('session', 'xyz789');
expect(win.localStorage.[2]('session')).to.equal('xyz789');
});setItem and getItem.removeItem or clear incorrectly.First, setItem stores the key 'session' with value 'xyz789'. Then, getItem retrieves it to verify the value.
Fill all three blanks to create a test that removes a local storage item and confirms it no longer exists.
cy.window().then((win) => {
win.localStorage.[1]('authToken', 'token123');
win.localStorage.[2]('authToken');
expect(win.localStorage.[3]('authToken')).to.be.null;
});clear instead of removeItem to delete a single key.First, setItem adds the 'authToken'. Then, removeItem deletes it. Finally, getItem returns null confirming removal.