-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added tests for ObjectStorage, improved its set and del methods
- Loading branch information
1 parent
ec6d6f0
commit db84e18
Showing
4 changed files
with
72 additions
and
12 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
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,60 @@ | ||
'use strict'; | ||
|
||
const ObjectStorage = require('../ObjectStorage'); | ||
|
||
describe('ObjectStorage', () => { | ||
describe('constructor', () => { | ||
it('should init with empty data property', () => { | ||
const objectStorage = new ObjectStorage(); | ||
expect(Object.keys(objectStorage.data)).toHaveLength(0); | ||
expect(objectStorage.data).toBeInstanceOf(Object); | ||
}); | ||
}); | ||
|
||
describe('set', () => { | ||
it('should set value to data property', () => { | ||
const objectStorage = new ObjectStorage(); | ||
objectStorage.set('prop', 'value'); | ||
expect(objectStorage.data.prop).toEqual('value'); | ||
}); | ||
|
||
it('should throw error if TTL was specified', () => { | ||
const objectStorage = new ObjectStorage(); | ||
expect(objectStorage.set('prop', 'value', 10)).rejects.toBeInstanceOf(Error); | ||
}); | ||
|
||
it('should return resolved promise without value', () => { | ||
const objectStorage = new ObjectStorage(); | ||
expect(objectStorage.set('prop', 'value')).resolves.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should fetch value from data property', () => { | ||
const objectStorage = new ObjectStorage(); | ||
objectStorage.set('prop', 'value'); | ||
expect(objectStorage.get('prop')).resolves.toEqual('value'); | ||
}); | ||
|
||
it('should return undefined if value was not found', () => { | ||
const objectStorage = new ObjectStorage(); | ||
expect(objectStorage.get('prop')).resolves.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('del', () => { | ||
it('should delete value in data property', () => { | ||
const objectStorage = new ObjectStorage(); | ||
objectStorage.set('prop', 'value'); | ||
expect(objectStorage.data.prop).toEqual('value'); | ||
objectStorage.del('prop'); | ||
expect(objectStorage.data.prop).toBeUndefined(); | ||
}); | ||
|
||
it('should return resolved promise without value', () => { | ||
const objectStorage = new ObjectStorage(); | ||
objectStorage.set('prop', 'value'); | ||
expect(objectStorage.del('prop')).resolves.toBeUndefined(); | ||
}); | ||
}) | ||
}); |
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