intl-tel-input 19.5.2 → 19.5.4

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.
@@ -200,8 +200,8 @@ class Iti {
200
200
  // process onlyCountries or excludeCountries array if present
201
201
  this._processAllCountries();
202
202
 
203
- // process the countryCodes map
204
- this._processCountryCodes();
203
+ // generate this.dialCodes and this.dialCodeToIso2Map
204
+ this._processDialCodes();
205
205
 
206
206
  // process the preferredCountries
207
207
  this._processPreferredCountries();
@@ -215,24 +215,24 @@ class Iti {
215
215
  }
216
216
  }
217
217
 
218
- // add a country code to this.countryCodes
219
- _addCountryCode(iso2, countryCode, priority) {
220
- if (countryCode.length > this.countryCodeMaxLen) {
221
- this.countryCodeMaxLen = countryCode.length;
218
+ // add a dial code to this.dialCodeToIso2Map
219
+ _addToDialCodeMap(iso2, dialCode, priority) {
220
+ if (dialCode.length > this.dialCodeMaxLen) {
221
+ this.dialCodeMaxLen = dialCode.length;
222
222
  }
223
- if (!this.countryCodes.hasOwnProperty(countryCode)) {
224
- this.countryCodes[countryCode] = [];
223
+ if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
224
+ this.dialCodeToIso2Map[dialCode] = [];
225
225
  }
226
- // bail if we already have this country for this countryCode
227
- for (let i = 0; i < this.countryCodes[countryCode].length; i++) {
228
- if (this.countryCodes[countryCode][i] === iso2) {
226
+ // bail if we already have this country for this dialCode
227
+ for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
228
+ if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
229
229
  return;
230
230
  }
231
231
  }
232
232
  // check for undefined as 0 is falsy
233
233
  const index =
234
- priority !== undefined ? priority : this.countryCodes[countryCode].length;
235
- this.countryCodes[countryCode][index] = iso2;
234
+ priority !== undefined ? priority : this.dialCodeToIso2Map[dialCode].length;
235
+ this.dialCodeToIso2Map[dialCode][index] = iso2;
236
236
  }
237
237
 
238
238
  // process onlyCountries or excludeCountries array if present
@@ -277,13 +277,24 @@ class Iti {
277
277
  return 0;
278
278
  }
279
279
 
280
- // process the countryCodes map
281
- _processCountryCodes() {
282
- this.countryCodeMaxLen = 0;
283
- // here we store just dial codes
280
+ // generate this.dialCodes and this.dialCodeToIso2Map
281
+ _processDialCodes() {
282
+ // here we store just dial codes, where the key is the dial code, and the value is true
283
+ // e.g. { 1: true, 7: true, 20: true, ... }
284
284
  this.dialCodes = {};
285
- // here we store "country codes" (both dial codes and their area codes)
286
- this.countryCodes = {};
285
+ this.dialCodeMaxLen = 0;
286
+
287
+ // here we map dialCodes (inc both dialCode and dialCode+areaCode) to iso2 codes
288
+ /* e.g.
289
+ * {
290
+ * 1: [ 'us', 'ca', ... ], # all NANP countries
291
+ * 12: [ 'us', 'ca', ... ], # subset of NANP countries
292
+ * 120: [ 'us', 'ca' ], # just US and Canada
293
+ * 1204: [ 'ca' ], # only Canada
294
+ * ...
295
+ * }
296
+ */
297
+ this.dialCodeToIso2Map = {};
287
298
 
288
299
  // first: add dial codes
289
300
  for (let i = 0; i < this.countries.length; i++) {
@@ -291,7 +302,7 @@ class Iti {
291
302
  if (!this.dialCodes[c.dialCode]) {
292
303
  this.dialCodes[c.dialCode] = true;
293
304
  }
294
- this._addCountryCode(c.iso2, c.dialCode, c.priority);
305
+ this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
295
306
  }
296
307
 
297
308
  // next: add area codes
@@ -302,7 +313,7 @@ class Iti {
302
313
  const c = this.countries[i];
303
314
  // area codes
304
315
  if (c.areaCodes) {
305
- const rootCountryCode = this.countryCodes[c.dialCode][0];
316
+ const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
306
317
  // for each area code
307
318
  for (let j = 0; j < c.areaCodes.length; j++) {
308
319
  const areaCode = c.areaCodes[j];
@@ -310,11 +321,11 @@ class Iti {
310
321
  for (let k = 1; k < areaCode.length; k++) {
311
322
  const partialDialCode = c.dialCode + areaCode.substr(0, k);
312
323
  // start with the root country, as that also matches this dial code
313
- this._addCountryCode(rootCountryCode, partialDialCode);
314
- this._addCountryCode(c.iso2, partialDialCode);
324
+ this._addToDialCodeMap(rootIso2Code, partialDialCode);
325
+ this._addToDialCodeMap(c.iso2, partialDialCode);
315
326
  }
316
327
  // add the full area code
317
- this._addCountryCode(c.iso2, c.dialCode + areaCode);
328
+ this._addToDialCodeMap(c.iso2, c.dialCode + areaCode);
318
329
  }
319
330
  }
320
331
  }
@@ -325,8 +336,8 @@ class Iti {
325
336
  _processPreferredCountries() {
326
337
  this.preferredCountries = [];
327
338
  for (let i = 0; i < this.options.preferredCountries.length; i++) {
328
- const countryCode = this.options.preferredCountries[i].toLowerCase();
329
- const countryData = this._getCountryData(countryCode, true);
339
+ const iso2 = this.options.preferredCountries[i].toLowerCase();
340
+ const countryData = this._getCountryData(iso2, true);
330
341
  if (countryData) {
331
342
  this.preferredCountries.push(countryData);
332
343
  }
@@ -425,7 +436,7 @@ class Iti {
425
436
  if (showFlags) {
426
437
  this.selectedFlagInner = this._createEl(
427
438
  "div",
428
- { class: "iti__flag iti__globe" },
439
+ { class: "iti__flag" },
429
440
  this.selectedFlag
430
441
  );
431
442
  }
@@ -540,7 +551,7 @@ class Iti {
540
551
  name: hiddenInputPhoneName
541
552
  });
542
553
 
543
- // Create hidden input for the selected country code
554
+ // Create hidden input for the selected country iso2 code
544
555
  this.hiddenInputCountry = this._createEl("input", {
545
556
  type: "hidden",
546
557
  name: hiddenInputCountryName
@@ -620,14 +631,15 @@ class Iti {
620
631
  if (dialCode && isRegionlessNanp) {
621
632
  // has intl dial code, is regionless nanp, and no initialCountry, so default to US
622
633
  this._setFlag("us");
623
- } else if (defaultToFirstCountry) {
634
+ } else if (defaultToFirstCountry && !val) {
624
635
  // no dial code and no initialCountry, so default to first in list
625
636
  this.defaultCountry = this.preferredCountries.length
626
637
  ? this.preferredCountries[0].iso2
627
638
  : this.countries[0].iso2;
628
- if (!val) {
629
- this._setFlag(this.defaultCountry);
630
- }
639
+ this._setFlag(this.defaultCountry);
640
+ } else {
641
+ // display the empty state (globe icon)
642
+ this._setFlag();
631
643
  }
632
644
  }
633
645
 
@@ -771,11 +783,11 @@ class Iti {
771
783
 
772
784
  if (typeof this.options.geoIpLookup === "function") {
773
785
  this.options.geoIpLookup(
774
- (countryCode = "") => {
775
- const lowerCountryCode = countryCode.toLowerCase();
776
- const isValidCountryCode = lowerCountryCode && this._getCountryData(lowerCountryCode, true);
777
- if (isValidCountryCode) {
778
- window.intlTelInputGlobals.autoCountry = lowerCountryCode;
786
+ (iso2 = "") => {
787
+ const iso2Lower = iso2.toLowerCase();
788
+ const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
789
+ if (isValidIso2) {
790
+ window.intlTelInputGlobals.autoCountry = iso2Lower;
779
791
  // tell all instances the auto country is ready
780
792
  // TODO: this should just be the current instances
781
793
  // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
@@ -1259,15 +1271,15 @@ class Iti {
1259
1271
  // try and extract valid dial code from input
1260
1272
  const dialCode = this._getDialCode(number, true);
1261
1273
  const numeric = this._getNumeric(number);
1262
- let countryCode = null;
1274
+ let iso2 = null;
1263
1275
  if (dialCode) {
1264
- const countryCodes = this.countryCodes[this._getNumeric(dialCode)];
1276
+ const iso2Codes = this.dialCodeToIso2Map[this._getNumeric(dialCode)];
1265
1277
  // check if the right country is already selected. this should be false if the number is
1266
1278
  // longer than the matched dial code because in this case we need to make sure that if
1267
1279
  // there are multiple country matches, that the first one is selected (note: we could
1268
1280
  // just check that here, but it requires the same loop that we already have later)
1269
1281
  const alreadySelected =
1270
- countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 &&
1282
+ iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 &&
1271
1283
  numeric.length <= dialCode.length - 1;
1272
1284
  const isRegionlessNanpNumber =
1273
1285
  selectedDialCode === "1" && this._isRegionlessNanp(numeric);
@@ -1277,11 +1289,11 @@ class Iti {
1277
1289
  // AND
1278
1290
  // B) the right country is not already selected
1279
1291
  if (!isRegionlessNanpNumber && !alreadySelected) {
1280
- // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
1292
+ // if using onlyCountries option, iso2Codes[0] may be empty, so we must find the first
1281
1293
  // non-empty index
1282
- for (let j = 0; j < countryCodes.length; j++) {
1283
- if (countryCodes[j]) {
1284
- countryCode = countryCodes[j];
1294
+ for (let j = 0; j < iso2Codes.length; j++) {
1295
+ if (iso2Codes[j]) {
1296
+ iso2 = iso2Codes[j];
1285
1297
  break;
1286
1298
  }
1287
1299
  }
@@ -1290,14 +1302,14 @@ class Iti {
1290
1302
  // invalid dial code, so empty
1291
1303
  // Note: use getNumeric here because the number has not been formatted yet, so could contain
1292
1304
  // bad chars
1293
- countryCode = "";
1305
+ iso2 = "";
1294
1306
  } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
1295
1307
  // if no selected flag, and user either clears the input, or just types a plus, then show default
1296
- countryCode = this.defaultCountry;
1308
+ iso2 = this.defaultCountry;
1297
1309
  }
1298
1310
 
1299
- if (countryCode !== null) {
1300
- return this._setFlag(countryCode);
1311
+ if (iso2 !== null) {
1312
+ return this._setFlag(iso2);
1301
1313
  }
1302
1314
  return false;
1303
1315
  }
@@ -1331,32 +1343,32 @@ class Iti {
1331
1343
  }
1332
1344
  }
1333
1345
 
1334
- // find the country data for the given country code
1346
+ // find the country data for the given iso2 code
1335
1347
  // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
1336
- _getCountryData(countryCode, allowFail) {
1348
+ _getCountryData(iso2, allowFail) {
1337
1349
  for (let i = 0; i < this.countries.length; i++) {
1338
- if (this.countries[i].iso2 === countryCode) {
1350
+ if (this.countries[i].iso2 === iso2) {
1339
1351
  return this.countries[i];
1340
1352
  }
1341
1353
  }
1342
1354
  if (allowFail) {
1343
1355
  return null;
1344
1356
  }
1345
- throw new Error(`No country data for '${countryCode}'`);
1357
+ throw new Error(`No country data for '${iso2}'`);
1346
1358
  }
1347
1359
 
1348
1360
  // select the given flag, update the placeholder, title, and the active list item
1349
1361
  // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
1350
- _setFlag(countryCode) {
1362
+ _setFlag(iso2) {
1351
1363
  const { allowDropdown, showSelectedDialCode, showFlags, countrySearch } = this.options;
1352
1364
 
1353
1365
  const prevCountry = this.selectedCountryData.iso2
1354
1366
  ? this.selectedCountryData
1355
1367
  : {};
1356
1368
 
1357
- // do this first as it will throw an error and stop if countryCode is invalid
1358
- this.selectedCountryData = countryCode
1359
- ? this._getCountryData(countryCode, false)
1369
+ // do this first as it will throw an error and stop if iso2 is invalid
1370
+ this.selectedCountryData = iso2
1371
+ ? this._getCountryData(iso2, false)
1360
1372
  : {};
1361
1373
  // update the defaultCountry - we only need the iso2 from now on, so just store that
1362
1374
  if (this.selectedCountryData.iso2) {
@@ -1364,14 +1376,14 @@ class Iti {
1364
1376
  }
1365
1377
 
1366
1378
  if (showFlags) {
1367
- const flagClass = countryCode ? `iti__${countryCode}` : 'iti__globe';
1379
+ const flagClass = iso2 ? `iti__${iso2}` : 'iti__globe';
1368
1380
  this.selectedFlagInner.setAttribute(
1369
1381
  "class",
1370
1382
  `iti__flag ${flagClass}`
1371
1383
  );
1372
1384
  }
1373
1385
 
1374
- this._setSelectedCountryFlagTitleAttribute(countryCode, showSelectedDialCode);
1386
+ this._setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode);
1375
1387
 
1376
1388
  if (showSelectedDialCode) {
1377
1389
  const dialCode = this.selectedCountryData.dialCode
@@ -1400,14 +1412,14 @@ class Iti {
1400
1412
  prevItem.classList.remove("iti__active");
1401
1413
  prevItem.setAttribute("aria-selected", "false");
1402
1414
  }
1403
- if (countryCode) {
1415
+ if (iso2) {
1404
1416
  // check if there is a preferred item first, else fall back to standard
1405
1417
  const nextItem =
1406
1418
  this.countryList.querySelector(
1407
- `#iti-${this.id}__item-${countryCode}-preferred`
1419
+ `#iti-${this.id}__item-${iso2}-preferred`
1408
1420
  ) ||
1409
1421
  this.countryList.querySelector(
1410
- `#iti-${this.id}__item-${countryCode}`
1422
+ `#iti-${this.id}__item-${iso2}`
1411
1423
  );
1412
1424
  nextItem.setAttribute("aria-selected", "true");
1413
1425
  nextItem.classList.add("iti__active");
@@ -1416,18 +1428,18 @@ class Iti {
1416
1428
  }
1417
1429
 
1418
1430
  // return if the flag has changed or not
1419
- return prevCountry.iso2 !== countryCode;
1431
+ return prevCountry.iso2 !== iso2;
1420
1432
  }
1421
1433
 
1422
- _setSelectedCountryFlagTitleAttribute(countryCode, showSelectedDialCode) {
1434
+ _setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode) {
1423
1435
  if (!this.selectedFlag) {
1424
1436
  return;
1425
1437
  }
1426
1438
 
1427
1439
  let title;
1428
- if (countryCode && !showSelectedDialCode) {
1440
+ if (iso2 && !showSelectedDialCode) {
1429
1441
  title = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`;
1430
- } else if (countryCode) {
1442
+ } else if (iso2) {
1431
1443
  // For screen reader output, we don't want to include the dial code in the reader output twice
1432
1444
  // so just use the selected country name here:
1433
1445
  title = this.selectedCountryData.name;
@@ -1619,7 +1631,7 @@ class Iti {
1619
1631
  numericChars += c;
1620
1632
  // if current numericChars make a valid dial code
1621
1633
  if (includeAreaCode) {
1622
- if (this.countryCodes[numericChars]) {
1634
+ if (this.dialCodeToIso2Map[numericChars]) {
1623
1635
  // store the actual raw string (useful for matching later)
1624
1636
  dialCode = number.substr(0, i + 1);
1625
1637
  }
@@ -1631,7 +1643,7 @@ class Iti {
1631
1643
  }
1632
1644
  }
1633
1645
  // stop searching as soon as we can - in this case when we hit max len
1634
- if (numericChars.length === this.countryCodeMaxLen) {
1646
+ if (numericChars.length === this.dialCodeMaxLen) {
1635
1647
  break;
1636
1648
  }
1637
1649
  }
@@ -1864,11 +1876,11 @@ class Iti {
1864
1876
  }
1865
1877
 
1866
1878
  // update the selected flag, and update the input val accordingly
1867
- setCountry(originalCountryCode) {
1868
- const countryCode = originalCountryCode.toLowerCase();
1879
+ setCountry(iso2) {
1880
+ const iso2Lower = iso2.toLowerCase();
1869
1881
  // check if already selected
1870
- if (this.selectedCountryData.iso2 !== countryCode) {
1871
- this._setFlag(countryCode);
1882
+ if (this.selectedCountryData.iso2 !== iso2Lower) {
1883
+ this._setFlag(iso2Lower);
1872
1884
  this._updateDialCode(this.selectedCountryData.dialCode);
1873
1885
  this._triggerCountryChange();
1874
1886
  }
@@ -105,10 +105,10 @@ var getFlagsContainerElement = function(i) {
105
105
  return i.parent().find(".iti__flag-container");
106
106
  };
107
107
 
108
- var selectFlag = function(countryCode, i) {
108
+ var selectFlag = function(iso2, i) {
109
109
  i = i || input;
110
110
  getSelectedFlagContainer(i)[0].click();
111
- getListElement(i).find("li[data-country-code='" + countryCode + "']")[0].click();
111
+ getListElement(i).find("li[data-country-code='" + iso2 + "']")[0].click();
112
112
  };
113
113
 
114
114
  var openCountryDropDown = function() {
@@ -4,12 +4,12 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
4
4
 
5
5
  var input2,
6
6
  iti2,
7
- afghanistanCountryCode = "af",
8
- albaniaCountryCode = "al",
9
- chinaCountryCode = "cn",
7
+ afghanistanIso2Code = "af",
8
+ albaniaIso2Code = "al",
9
+ chinaIso2Code = "cn",
10
10
  chinaDialCode = "+86",
11
- koreaCountryCode = 'kr',
12
- russiaCountryCode = 'ru';
11
+ koreaIso2Code = 'kr',
12
+ russiaIso2Code = 'ru';
13
13
 
14
14
  beforeEach(function() {
15
15
  intlSetup();
@@ -17,11 +17,11 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
17
17
  input2 = $("<input>").wrap("div");
18
18
 
19
19
  iti = window.intlTelInput(input[0], {
20
- onlyCountries: [afghanistanCountryCode, chinaCountryCode],
20
+ onlyCountries: [afghanistanIso2Code, chinaIso2Code],
21
21
  nationalMode: false,
22
22
  });
23
23
  iti2 = window.intlTelInput(input2[0], {
24
- onlyCountries: [albaniaCountryCode, chinaCountryCode, koreaCountryCode, russiaCountryCode],
24
+ onlyCountries: [albaniaIso2Code, chinaIso2Code, koreaIso2Code, russiaIso2Code],
25
25
  nationalMode: false,
26
26
  });
27
27
  $("body").append(getParentElement(input)).append(getParentElement(input2));
@@ -40,21 +40,21 @@ describe("multiple instances: init plugin (with nationalMode=false) to test mult
40
40
  });
41
41
 
42
42
  it("instances have different default countries selected", function() {
43
- expect(getSelectedFlagElement()).toHaveClass(`iti__${afghanistanCountryCode}`);
44
- expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
43
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${afghanistanIso2Code}`);
44
+ expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
45
45
  });
46
46
 
47
47
  it("selecting an item from the first input dropdown only updates the flag on that input", function() {
48
- selectFlag(chinaCountryCode);
49
- expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
50
- expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
48
+ selectFlag(chinaIso2Code);
49
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
50
+ expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
51
51
  });
52
52
 
53
53
  it("updating the number on the first input only updates the flag on that input", function() {
54
54
  input.val(chinaDialCode + " 123456");
55
55
  triggerKeyOnInput(" ");
56
- expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
57
- expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
56
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
57
+ expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaIso2Code}`);
58
58
  });
59
59
 
60
60
 
@@ -52,14 +52,14 @@ describe("using dropdown: init plugin on normal input with nationalMode=false, a
52
52
 
53
53
  describe("selecting a new country item", function() {
54
54
 
55
- var countryCode = "ca";
55
+ var iso2Code = "ca";
56
56
 
57
57
  beforeEach(function() {
58
- getListElement().find("li[data-country-code='" + countryCode + "']")[0].click();
58
+ getListElement().find("li[data-country-code='" + iso2Code + "']")[0].click();
59
59
  });
60
60
 
61
61
  it("updates the selected flag", function() {
62
- expect(getSelectedFlagElement()).toHaveClass(`iti__${countryCode}`);
62
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2Code}`);
63
63
  });
64
64
 
65
65
  it("updates the dial code", function() {
@@ -69,7 +69,7 @@ describe("using dropdown: init plugin on normal input with nationalMode=false, a
69
69
  // this was a bug
70
70
  it("adding a space doesnt reset to the default country for that dial code", function() {
71
71
  triggerKeyOnInput(" ");
72
- expect(getSelectedFlagElement()).toHaveClass(`iti__${countryCode}`);
72
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2Code}`);
73
73
  });
74
74
 
75
75
  });
@@ -22,7 +22,7 @@ describe("getValidationError:", function() {
22
22
  expect(iti.getValidationError()).toEqual(intlTelInputUtils.validationError.TOO_LONG);
23
23
  });
24
24
 
25
- it("returns the right error for a number with an invalid country code", function() {
25
+ it("returns the right error for a number with an invalid iso2 code", function() {
26
26
  iti.setNumber("+969");
27
27
  expect(iti.getValidationError()).toEqual(intlTelInputUtils.validationError.INVALID_COUNTRY_CODE);
28
28
  });
@@ -2,13 +2,13 @@
2
2
 
3
3
  describe("setCountry: init plugin and calling public method setCountry()", function() {
4
4
 
5
- var countryCode = "gb";
5
+ var iso2 = "gb";
6
6
 
7
7
  beforeEach(function() {
8
8
  intlSetup();
9
9
  input = $("<input>").wrap("div");
10
10
  iti = window.intlTelInput(input[0]);
11
- iti.setCountry(countryCode);
11
+ iti.setCountry(iso2);
12
12
  });
13
13
 
14
14
  afterEach(function() {
@@ -16,7 +16,7 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
16
16
  });
17
17
 
18
18
  it("updates the selected flag", function() {
19
- expect(getSelectedFlagElement()).toHaveClass(`iti__${countryCode}`);
19
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${iso2}`);
20
20
  });
21
21
 
22
22
  it("does not insert the dial code", function() {
@@ -30,7 +30,7 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
30
30
  showFlags: true,
31
31
  showSelectedDialCode: false,
32
32
  });
33
- iti.setCountry(countryCode);
33
+ iti.setCountry(iso2);
34
34
  });
35
35
 
36
36
  it("has the country name and dial code in the flag's title", function() {
@@ -44,27 +44,12 @@ describe("setCountry: init plugin and calling public method setCountry()", funct
44
44
  showFlags: true,
45
45
  showSelectedDialCode: true,
46
46
  });
47
- iti.setCountry(countryCode);
47
+ iti.setCountry(iso2);
48
48
  });
49
49
 
50
50
  it("has the country name but not the dial code in the flag's title", function() {
51
51
  expect(getSelectedFlagContainer().attr("title")).toEqual("United Kingdom");
52
52
  });
53
53
  });
54
-
55
-
56
- // setCountry errors out when country code is undefined, so we can likely remove this scenario and make country code a required param
57
- describe("when countryCode is falsey", function() {
58
- // beforeEach(function() {
59
- // iti = window.intlTelInput(input[0], {
60
- // showFlags: true,
61
- // });
62
- // iti.setCountry();
63
- // });
64
-
65
- it("sets the flag's title as Unknown", function() {
66
- // expect(getSelectedFlagContainer().attr("title")).toEqual("Unknown");
67
- });
68
- })
69
54
  });
70
55
  });
@@ -17,18 +17,18 @@ describe("onlyCountries option:", function() {
17
17
 
18
18
  describe("init plugin with onlyCountries set to japan, china and korea", function() {
19
19
 
20
- var chinaCountryCode = "cn";
20
+ var chinaIso2Code = "cn";
21
21
 
22
22
  beforeEach(function() {
23
23
  // China and Japan (note that none of the default preferredCountries are included here, so wont be in the list)
24
- onlyCountries = ['jp', chinaCountryCode, 'kr'];
24
+ onlyCountries = ['jp', chinaIso2Code, 'kr'];
25
25
  iti = window.intlTelInput(input[0], {
26
26
  onlyCountries: onlyCountries,
27
27
  });
28
28
  });
29
29
 
30
30
  it("defaults to the first onlyCountries alphabetically", function() {
31
- expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
31
+ expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaIso2Code}`);
32
32
  });
33
33
 
34
34
  it("has the right number of list items", function() {