Skip to content

Commit

Permalink
fix(perfume): to not call storage.estimate if it's not supported (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
glebv committed Aug 10, 2020
1 parent ac0f4d1 commit 2db4fda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions __tests__/perfume.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ describe('Perfume', () => {
expect(spy.mock.calls.length).toEqual(0);
});

it('when WN.storage.estimate() is not defined should not call it', () => {
(WN as any) = mock.navigator();
const spy = jest.spyOn(WN.storage, 'estimate');
(WN as any).storage.estimate = undefined;
expect(() => new Perfume()).not.toThrow(TypeError);
expect(spy.mock.calls.length).toEqual(0);
});

it('when navigator is supported should call WN.storage.estimate()', () => {
(WN as any) = mock.navigator();
const spy = jest.spyOn(WN.storage, 'estimate');
Expand Down
2 changes: 1 addition & 1 deletion src/perfume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class Perfume {
// Log Network Information
logData('networkInformation', getNetworkInformation());
// Let's estimate our storage capacity
if (WN && WN.storage) {
if (WN && WN.storage && typeof WN.storage.estimate === 'function') {
WN.storage.estimate().then(reportStorageEstimate);
}
}
Expand Down

0 comments on commit 2db4fda

Please sign in to comment.