Skip to content

Commit 12473f3

Browse files
committed
add sinon and create a fake localStorage for jest
1 parent a9688ac commit 12473f3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

config/localStorageMock.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class LocalStorageMock {
2+
constructor() {
3+
this.store = {};
4+
}
5+
6+
clear() {
7+
this.store = {};
8+
}
9+
10+
getItem(key) {
11+
return this.store[key];
12+
}
13+
14+
setItem(key, value) {
15+
this.store[key] = value.toString();
16+
}
17+
18+
removeItem(key) {
19+
delete this.store[key];
20+
}
21+
};
22+
23+
global.localStorage = new LocalStorageMock;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"promise": "7.1.1",
133133
"react-dev-utils": "^0.5.2",
134134
"sass-loader": "^6.0.5",
135+
"sinon": "^2.3.4",
135136
"style-loader": "0.13.1",
136137
"supertest": "~3.0.0",
137138
"url-loader": "0.5.7",
@@ -145,7 +146,8 @@
145146
"src/**/*.{js,jsx}"
146147
],
147148
"setupFiles": [
148-
"<rootDir>/config/polyfills.js"
149+
"<rootDir>/config/polyfills.js",
150+
"<rootDir>/config/localStorageMock.js"
149151
],
150152
"testPathIgnorePatterns": [
151153
"<rootDir>[/\\\\](build|docs|node_modules|scripts|clicktests)[/\\\\]"

0 commit comments

Comments
 (0)