Introduce Jest Unit Testing framework

This commit is contained in:
Chi Vinh Le
2017-10-03 21:08:02 +07:00
parent 5a4bf7a223
commit c1f7ef4f32
10 changed files with 901 additions and 105 deletions
+38
View File
@@ -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();