-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ensure storageEngine implements correct interface
In order to prevent implementation errors, we want to check that storageEngine implements the correct methods This replies to #1483 (comment)
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PouchLocalStorage } from './localStorage' | ||
|
||
describe('LocalStorage', () => { | ||
describe('Type assertion', () => { | ||
it('should throw if setItem method is missing', () => { | ||
expect(() => { | ||
new PouchLocalStorage({ | ||
getItem: jest.fn(), | ||
removeItem: jest.fn() | ||
}) | ||
}).toThrow( | ||
'Provided storageEngine is missing the following methods: setItem' | ||
) | ||
}) | ||
|
||
it('should throw if getItem method is missing', () => { | ||
expect(() => { | ||
new PouchLocalStorage({ | ||
setItem: jest.fn(), | ||
removeItem: jest.fn() | ||
}) | ||
}).toThrow( | ||
'Provided storageEngine is missing the following methods: getItem' | ||
) | ||
}) | ||
|
||
it('should throw if removeItem method is missing', () => { | ||
expect(() => { | ||
new PouchLocalStorage({ | ||
getItem: jest.fn(), | ||
setItem: jest.fn() | ||
}) | ||
}).toThrow( | ||
'Provided storageEngine is missing the following methods: removeItem' | ||
) | ||
}) | ||
|
||
it('should throw if multiple methods are missing', () => { | ||
expect(() => { | ||
new PouchLocalStorage({ | ||
getItem: jest.fn() | ||
}) | ||
}).toThrow( | ||
'Provided storageEngine is missing the following methods: setItem, removeItem' | ||
) | ||
}) | ||
}) | ||
}) |