Skip to content

Commit d699266

Browse files
committed
Updated for tests and linting
1 parent d236005 commit d699266

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

Gruntfile.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(grunt) {
1616
],
1717
configFile: 'test/karma.conf.js',
1818
reporters: ['dots'],
19-
singleRun: false
19+
singleRun: true
2020
},
2121
unit: {}
2222
},
@@ -29,9 +29,7 @@ module.exports = function(grunt) {
2929
},
3030
dev: {
3131
src: ['angular-local-storage.js'],
32-
options: {
33-
jshintrc: '.jshintrc',
34-
}
32+
options: {}
3533
},
3634
test: {
3735
src: ['test/spec/**/*.js'],

angular-local-storage.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ angularLocalStorage.provider('localStorageService', function() {
215215
// Should be used mostly for development purposes
216216
var clearAllFromLocalStorage = function (regularExpression) {
217217

218-
var regularExpression = regularExpression || "";
218+
regularExpression = regularExpression || "";
219219
//accounting for the '.' in the prefix when creating a regex
220-
var tempPrefix = prefix.slice(0, -1) + "\.";
221-
var testRegex = RegExp(tempPrefix + regularExpression);
220+
var tempPrefix = prefix.slice(0, -1);
221+
var testRegex = new RegExp(tempPrefix + '.' + regularExpression);
222222

223223
if (!browserSupportsLocalStorage) {
224224
$rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED');
@@ -357,7 +357,7 @@ angularLocalStorage.provider('localStorageService', function() {
357357
clearAll: clearAllFromCookies
358358
}
359359
};
360-
}]
360+
}];
361361
});
362362
}).call(this);
363363

test/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ module.exports = function(config) {
4040
logLevel: config.LOG_INFO,
4141

4242
// web server port
43-
port: 8080,
43+
port: 8999,
4444

4545
// Continuous Integration mode
4646
// if true, it capture browsers, run tests and exit
47-
singleRun: false
47+
singleRun: true,
4848
});
4949
};

test/spec/test.js

+52-48
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
describe('Tests functionality of the localStorage module', function(){
2-
beforeEach(module('LocalStorageModule', function(localStorageServiceProvider){
3-
p = localStorageServiceProvider;
4-
}));
5-
var ls, store = [];
6-
beforeEach(inject(function(_localStorageService_){
7-
ls = _localStorageService_;
8-
spyOn(ls, 'get').andCallFake(function(key){
9-
if(store[key].charAt(0) === "{" || store[key].charAt(0) === "["){
10-
return angular.fromJson(store[key]);
11-
}else{
12-
return store[key];
13-
}
14-
});
15-
16-
spyOn(ls, 'set').andCallFake(function(key, val){
17-
if(angular.isObject(val) || angular.isArray(val)){
18-
val = angular.toJson(val);
19-
}
20-
if(angular.isNumber(val)){
21-
val = val.toString();
22-
}
23-
return store[key] = val;
24-
});
25-
26-
spyOn(ls, 'clearAll').andCallFake(function(){
27-
store = {};
28-
return store;
29-
});
30-
}));
31-
32-
it("Should add a value to my local storage", function(){
33-
var n = 234;
34-
ls.set('test', n);
35-
//Since localStorage makes the value a string, we look for the '234' and not 234
36-
expect(ls.get('test')).toBe('234');
37-
38-
var obj = { key: 'val' };
39-
ls.set('object', obj);
40-
var res = ls.get('object');
41-
expect(res.key).toBe('val');
1+
'use strict';
422

3+
describe('Tests functionality of the localStorage module', function() {
4+
var ls, p, store = [];
5+
6+
beforeEach(module('LocalStorageModule', function(localStorageServiceProvider) {
7+
p = localStorageServiceProvider;
8+
}));
9+
10+
beforeEach(inject(function(_localStorageService_) {
11+
ls = _localStorageService_;
12+
spyOn(ls, 'get').andCallFake(function(key) {
13+
if (store[key].charAt(0) === '{' || store[key].charAt(0) === '[') {
14+
return angular.fromJson(store[key]);
15+
} else {
16+
return store[key];
17+
}
4318
});
4419

45-
it('Should allow me to set a prefix', function(){
46-
p.setPrefix("myPref");
47-
expect(p.prefix).toBe("myPref");
20+
spyOn(ls, 'set').andCallFake(function(key, val) {
21+
if (angular.isObject(val) || angular.isArray(val)) {
22+
val = angular.toJson(val);
23+
}
24+
if (angular.isNumber(val)){
25+
val = val.toString();
26+
}
27+
store[key] = val;
28+
return store[key];
4829
});
4930

50-
it('Should allow me to set the cookie values', function(){
51-
p.setStorageCookie(60, '/path');
52-
expect(p.cookie.expiry).toBe(60);
53-
expect(p.cookie.path).toBe('/path');
31+
spyOn(ls, 'clearAll').andCallFake(function() {
32+
store = {};
33+
return store;
5434
});
35+
}));
36+
37+
it('Should add a value to my local storage', function() {
38+
var n = 234;
39+
ls.set('test', n);
40+
//Since localStorage makes the value a string, we look for the '234' and not 234
41+
expect(ls.get('test')).toBe('234');
42+
43+
var obj = { key: 'val' };
44+
ls.set('object', obj);
45+
var res = ls.get('object');
46+
expect(res.key).toBe('val');
47+
});
48+
49+
it('Should allow me to set a prefix', function() {
50+
p.setPrefix('myPref');
51+
expect(p.prefix).toBe('myPref');
52+
});
53+
54+
it('Should allow me to set the cookie values', function() {
55+
p.setStorageCookie(60, '/path');
56+
expect(p.cookie.expiry).toBe(60);
57+
expect(p.cookie.path).toBe('/path');
58+
});
5559
});

0 commit comments

Comments
 (0)