Skip to content

Commit

Permalink
fix: bugfix when last() with null value throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielrousseaufilion committed Feb 9, 2017
1 parent 708aa9f commit 5b3d175
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/core/src/localstorageexpiry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('core/LocalStorageExpiry', () => {
expect(service.last()).toEqual(expected);
}));

it('last() remove value and return null if param is null', inject([LocalStorageExpiry], (service: LocalStorageExpiry) => {
let expected = null;
expect(service.last(expected)).toEqual(expected);
expect(service.last()).toEqual(expected);
}));

it('setExpiryKey() sets the key name of expiry', inject([LocalStorageExpiry], (service: LocalStorageExpiry) => {
expect(service.getExpiryKey()).toBe('expiry');
service.setExpiryKey('name');
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/localstorageexpiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class LocalStorageExpiry extends IdleExpiry {
}

private setExpiry(value: Date) {
this.localStorage.setItem(this.expiryKey, value.getTime().toString());
if (value) {
this.localStorage.setItem(this.expiryKey, value.getTime().toString());
} else {
this.localStorage.removeItem(this.expiryKey);
}
}

}

0 comments on commit 5b3d175

Please sign in to comment.