Conditions | 1 |
Paths | 1 |
Total Lines | 94 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // load cookie lib |
||
67 | describe('argument oAttribute', function() { |
||
68 | it('should be applied correctly', function() { |
||
69 | cookiejs.set.bind(null, 'test', 'test', { |
||
70 | domain: '.somedomain.com', |
||
71 | path: '/somepath', |
||
72 | 'max-age': '60', |
||
73 | secure: true, |
||
74 | expires: 'atsometime' |
||
75 | })(); |
||
76 | expect(cookiejs.global.cookie).toEqual( |
||
77 | 'test=test;domain=.somedomain.com;path=/somepath;max-age=60;secure;expires=atsometime' |
||
78 | ); |
||
79 | }); |
||
80 | |||
81 | it('should be of type object', function() { |
||
82 | expect(cookiejs.set.bind(null, 'test', 'test', [])).toThrowError( |
||
83 | TypeError |
||
84 | ); |
||
85 | expect(cookiejs.set.bind(null, 'test', 'test', false)).toThrowError( |
||
86 | TypeError |
||
87 | ); |
||
88 | expect(cookiejs.set.bind(null, 'test', 'test', 'options')).toThrowError( |
||
89 | TypeError |
||
90 | ); |
||
91 | expect(cookiejs.set.bind(null, 'test', 'test', 0)).toThrowError( |
||
92 | TypeError |
||
93 | ); |
||
94 | }); |
||
95 | |||
96 | it('property domain should be of type string', function() { |
||
97 | expect( |
||
98 | cookiejs.set.bind(null, 'test', 'test', { |
||
99 | domain: 1 |
||
100 | }) |
||
101 | ).toThrowError(TypeError); |
||
102 | expect( |
||
103 | cookiejs.set.bind(null, 'test', 'test', { |
||
104 | domain: [] |
||
105 | }) |
||
106 | ).toThrowError(TypeError); |
||
107 | }); |
||
108 | |||
109 | it('property path should be of type string', function() { |
||
110 | expect( |
||
111 | cookiejs.set.bind(null, 'test', 'test', { |
||
112 | path: 1 |
||
113 | }) |
||
114 | ).toThrowError(TypeError); |
||
115 | expect( |
||
116 | cookiejs.set.bind(null, 'test', 'test', { |
||
117 | path: {} |
||
118 | }) |
||
119 | ).toThrowError(TypeError); |
||
120 | }); |
||
121 | |||
122 | it('property max-age should be of type string', function() { |
||
123 | expect( |
||
124 | cookiejs.set.bind(null, 'test', 'test', { |
||
125 | 'max-age': function() {} |
||
126 | }) |
||
127 | ).toThrowError(TypeError); |
||
128 | expect( |
||
129 | cookiejs.set.bind(null, 'test', 'test', { |
||
130 | 'max-age': 60 |
||
131 | }) |
||
132 | ).toThrowError(TypeError); |
||
133 | }); |
||
134 | |||
135 | it('property expires should be of type string', function() { |
||
136 | expect( |
||
137 | cookiejs.set.bind(null, 'test', 'test', { |
||
138 | expires: 123 |
||
139 | }) |
||
140 | ).toThrowError(TypeError); |
||
141 | }); |
||
142 | |||
143 | it('property secure should be of type boolean', function() { |
||
144 | expect( |
||
145 | cookiejs.set.bind(null, 'test', 'test', { |
||
146 | secure: 0 |
||
147 | }) |
||
148 | ).toThrowError(TypeError); |
||
149 | expect( |
||
150 | cookiejs.set.bind(null, 'test', 'test', { |
||
151 | secure: 1 |
||
152 | }) |
||
153 | ).toThrowError(TypeError); |
||
154 | expect( |
||
155 | cookiejs.set.bind(null, 'test', 'test', { |
||
156 | secure: 'false' |
||
157 | }) |
||
158 | ).toThrowError(TypeError); |
||
159 | }); |
||
160 | }); |
||
161 | |||
203 |