mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
Introduce Jest Unit Testing framework
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Enzyme from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-15';
|
||||
|
||||
Enzyme.configure({adapter: new Adapter()});
|
||||
|
||||
// Storage Mock
|
||||
|
||||
// TODO: If our code is written well, there shouldn't be a hardcoded dependency
|
||||
// to the local storage, and this global mock wouldn't be needed.
|
||||
|
||||
function storageMock() {
|
||||
let storage = {};
|
||||
|
||||
return {
|
||||
setItem: function(key, value) {
|
||||
storage[key] = value || '';
|
||||
},
|
||||
getItem: function(key) {
|
||||
return key in storage ? storage[key] : null;
|
||||
},
|
||||
removeItem: function(key) {
|
||||
delete storage[key];
|
||||
},
|
||||
get length() {
|
||||
return Object.keys(storage).length;
|
||||
},
|
||||
key: function(i) {
|
||||
let keys = Object.keys(storage);
|
||||
return keys[i] || null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// mock the localStorage
|
||||
window.localStorage = storageMock();
|
||||
|
||||
// mock the sessionStorage
|
||||
window.sessionStorage = storageMock();
|
||||
Reference in New Issue
Block a user