forked from bcgov/range-web
-
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.
add unit tests to localStorage helper and API.js -> api.js
- Loading branch information
Kyubinhan
committed
Sep 25, 2018
1 parent
dd2482f
commit eced189
Showing
17 changed files
with
1,302 additions
and
646 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,36 @@ | ||
/* eslint-disable no-underscore-dangle, dot-notation */ | ||
|
||
import { | ||
saveDataInLocalStorage, | ||
getDataFromLocalStorage, | ||
deleteDataFromLocalStorage, | ||
} from '../../utils'; | ||
// Please view https://www.npmjs.com/package/jest-localstorage-mock for usage of the local storage mock | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
saveDataInLocalStorage('validKey', { a: 123 }); | ||
saveDataInLocalStorage('anotherKey', 'a random string'); | ||
}); | ||
|
||
describe('Local Storage Helper Methods', () => { | ||
test('saveDataInLocalStorage stores data that is passed in', () => { | ||
expect(localStorage.__STORE__['validKey']).toBe(JSON.stringify({ a: 123 })); | ||
expect(localStorage.__STORE__['anotherKey']).toBe('a random string'); | ||
}); | ||
|
||
test('getDataInLocalStorage gets data when passed a valid key', () => { | ||
expect(getDataFromLocalStorage('validKey')).toEqual({ a: 123 }); | ||
expect(getDataFromLocalStorage('anotherKey')).toBe('a random string'); | ||
}); | ||
|
||
test('getDataFromLocalStorage returns undefined when an invalid key is passed in', () => { | ||
expect(getDataFromLocalStorage('asdlkjf;asd')).toBe(undefined); | ||
expect(getDataFromLocalStorage(123123)).toBe(undefined); | ||
expect(getDataFromLocalStorage({ a: true })).toBe(undefined); | ||
}); | ||
|
||
test('deleteDataFromLocalStorage deletes data from storage when key is passed in', () => { | ||
deleteDataFromLocalStorage('validKey'); | ||
expect(getDataFromLocalStorage('validKey')).toBe(undefined); | ||
}); | ||
}); |
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