我想测试localStorage
每当我调用我的函数时是否清除了。
零件
ngOnInit() {
// Logout on reaching login screen so we can login
this.authService.logout();
}
身份验证服务
logout() {
// remove logged in user from localStorage
localStorage.removeItem('currentUser');
}
测试
fit('ngOnInit should logout user stored in localStorage', () => {
// Exmample data stored as token
localStorage.setItem('token', 'someUserToken');
component.ngOnInit();
expect(localStorage.getItem('token')).toEqual('{}');
});
有什么办法可以做到这一点?