@osimatic/helpers-js 1.5.24 → 1.5.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/form_date.js CHANGED
@@ -144,6 +144,9 @@ class FormDate {
144
144
 
145
145
  static fillYearSelect(select, nbYearsBefore=5, nbYearsAfter=0) {
146
146
  select = toEl(select);
147
+ if (!select) {
148
+ return;
149
+ }
147
150
  const currentDate = new Date();
148
151
  for (let year=currentDate.getUTCFullYear()-nbYearsBefore; year<=(currentDate.getUTCFullYear()+nbYearsAfter); year++) {
149
152
  select.insertAdjacentHTML('beforeend', '<option value="'+year+'">'+year+'</option>');
@@ -152,6 +155,9 @@ class FormDate {
152
155
 
153
156
  static fillMonthSelect(select, locale) {
154
157
  select = toEl(select);
158
+ if (!select) {
159
+ return;
160
+ }
155
161
  for (let month=1; month<=12; month++) {
156
162
  select.insertAdjacentHTML('beforeend', '<option value="'+month+'">'+DateTime.getMonthNameByMonth(month, locale).capitalize()+'</option>');
157
163
  }
@@ -159,6 +165,9 @@ class FormDate {
159
165
 
160
166
  static fillDayOfWeekSelect(select, locale) {
161
167
  select = toEl(select);
168
+ if (!select) {
169
+ return;
170
+ }
162
171
  for (let dayOfWeek=1; dayOfWeek<=7; dayOfWeek++) {
163
172
  select.insertAdjacentHTML('beforeend', '<option value="'+dayOfWeek+'">'+DateTime.getDayNameByDayOfWeek(dayOfWeek, locale).capitalize()+'</option>');
164
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.24",
3
+ "version": "1.5.25",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -182,6 +182,11 @@ describe('FormDate', () => {
182
182
  mockSelect = { insertAdjacentHTML: jest.fn() };
183
183
  });
184
184
 
185
+ test('should do nothing if element does not exist', () => {
186
+ expect(() => FormDate.fillYearSelect(null)).not.toThrow();
187
+ expect(() => FormDate.fillYearSelect(undefined)).not.toThrow();
188
+ });
189
+
185
190
  test('should fill select with years from 5 years before to current year', () => {
186
191
  FormDate.fillYearSelect(mockSelect);
187
192
 
@@ -259,6 +264,11 @@ describe('FormDate', () => {
259
264
  }
260
265
  });
261
266
 
267
+ test('should do nothing if element does not exist', () => {
268
+ expect(() => FormDate.fillMonthSelect(null)).not.toThrow();
269
+ expect(() => FormDate.fillMonthSelect(undefined)).not.toThrow();
270
+ });
271
+
262
272
  test('should fill select with 12 months', () => {
263
273
  FormDate.fillMonthSelect(mockSelect, 'fr');
264
274
 
@@ -281,6 +291,11 @@ describe('FormDate', () => {
281
291
  }
282
292
  });
283
293
 
294
+ test('should do nothing if element does not exist', () => {
295
+ expect(() => FormDate.fillDayOfWeekSelect(null)).not.toThrow();
296
+ expect(() => FormDate.fillDayOfWeekSelect(undefined)).not.toThrow();
297
+ });
298
+
284
299
  test('should fill select with 7 days of week', () => {
285
300
  FormDate.fillDayOfWeekSelect(mockSelect, 'fr');
286
301