I am trying to clear my localstorage when I am logging out of the application. I want to write a unit test case in Jasmine to check if this task is performed when logout function is run. I am writing test cases for the first time so got stuck in the approach.
In my compoment.ts file I have a logout function:
logout() {
location.href = "/";
localstorage.clear();
}
spec.ts file
beforeEach(function () {
var store = {};
spyOn(localStorage, 'getItem').andCallFake(function (key) {
return null;
});
});
I don't know if this is a correct approach to write the test case for this particular requirement or which one among unit or integration test cases is actually valid for this situation.