{
let expected = '';
const onSelectFlag = (currentNumber, countryData, fullNumber, isValid) => {
- expected = Object.assign({}, { currentNumber, fullNumber, isValid, ...countryData });
+ expected = Object.assign(
+ {},
+ { currentNumber, fullNumber, isValid, ...countryData }
+ );
};
this.params.onSelectFlag = onSelectFlag;
@@ -451,9 +491,11 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
const inputComponent = subject.find(TelInput);
const countryListComponent = subject.find(CountryList);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('change', { target: { value: '+8109012345678' } });
@@ -479,12 +521,16 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
this.params.nationalMode = true;
const subject = this.makeSubject();
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
- expect(subject.instance().formatNumber('+886 912 345 678')).toBe('0912 345 678');
+ expect(subject.instance().formatNumber('+886 912 345 678')).toBe(
+ '0912 345 678'
+ );
});
it('should highlight country from preferred list', async () => {
diff --git a/src/components/__tests__/RootModal.test.js b/src/components/__tests__/RootModal.test.js
index 56324f377..6584a0865 100644
--- a/src/components/__tests__/RootModal.test.js
+++ b/src/components/__tests__/RootModal.test.js
@@ -2,7 +2,8 @@ import React from 'react';
import { mount } from 'enzyme';
import RootModal from '../RootModal';
-describe('RootModal', function () { // eslint-disable-line func-names
+// eslint-disable-next-line func-names
+describe('RootModal', function() {
beforeEach(() => {
jest.resetModules();
@@ -13,7 +14,7 @@ describe('RootModal', function () { // eslint-disable-line func-names
,
{
attachTo: document.body,
- },
+ }
);
};
});
diff --git a/src/components/__tests__/TelInput.test.js b/src/components/__tests__/TelInput.test.js
index b052e6972..8c41a2557 100644
--- a/src/components/__tests__/TelInput.test.js
+++ b/src/components/__tests__/TelInput.test.js
@@ -7,7 +7,8 @@ import IntlTelInput from '../IntlTelInputApp';
import TelInput from '../TelInput';
import FlagDropDown from '../FlagDropDown';
-describe('TelInput', function () { // eslint-disable-line func-names
+// eslint-disable-next-line func-names
+describe('TelInput', function() {
let libphonenumberUtils;
let getScript;
let xhr;
@@ -26,12 +27,13 @@ describe('TelInput', function () { // eslint-disable-line func-names
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
- xhr.onCreate = (req) => { requests.push(req); };
+ xhr.onCreate = req => {
+ requests.push(req);
+ };
document.body.innerHTML = '';
window.intlTelInputUtils = undefined;
- getScript = () =>
- document.getElementsByTagName('script')[0];
+ getScript = () => document.getElementsByTagName('script')[0];
this.params = {
css: ['intl-tel-input', 'form-control phoneNumber'],
@@ -42,13 +44,9 @@ describe('TelInput', function () { // eslint-disable-line func-names
utilsScript: 'assets/libphonenumber.js',
};
this.makeSubject = () => {
- return mount(
- , {
- attachTo: document.querySelector('#root'),
- },
- );
+ return mount(, {
+ attachTo: document.querySelector('#root'),
+ });
};
});
@@ -68,8 +66,16 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('onPhoneNumberChange without utilsScript', () => {
let expected = '';
- const onPhoneNumberChange = (isValid, newNumber, countryData, fullNumber, ext) => {
- expected = `${isValid},${newNumber},${countryData.iso2},${fullNumber},${ext}`;
+ const onPhoneNumberChange = (
+ isValid,
+ newNumber,
+ countryData,
+ fullNumber,
+ ext
+ ) => {
+ expected = `${isValid},${newNumber},${
+ countryData.iso2
+ },${fullNumber},${ext}`;
};
this.params.utilsScript = '';
@@ -85,9 +91,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = await this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
expect(inputComponent.props().value).toBe('0999 123 456');
@@ -97,7 +105,9 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- expect(inputComponent.find('.form-control.phoneNumber').length).toBeTruthy();
+ expect(
+ inputComponent.find('.form-control.phoneNumber').length
+ ).toBeTruthy();
});
it('should not focused on render', () => {
@@ -105,7 +115,10 @@ describe('TelInput', function () { // eslint-disable-line func-names
let focused = false;
- IntlTelInput.prototype.selectFlag = function selectFlag(countryCode, setFocus = true) {
+ IntlTelInput.prototype.selectFlag = function selectFlag(
+ countryCode,
+ setFocus = true
+ ) {
focused = focused || setFocus;
initialSelectFlag.call(this, countryCode, setFocus);
};
@@ -121,7 +134,6 @@ describe('TelInput', function () { // eslint-disable-line func-names
expect(focused).toBeFalsy();
});
-
it('should has "kr" in preferred countries state', () => {
this.params = {
...this.params,
@@ -166,9 +178,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('focus');
@@ -196,9 +210,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('focus');
@@ -232,9 +248,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('utils loaded', () => {
this.makeSubject();
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
expect(typeof window.intlTelInputUtils === 'object');
@@ -243,17 +261,27 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('onPhoneNumberChange', () => {
let expected = '';
- const onPhoneNumberChange = (isValid, newNumber, countryData, fullNumber, ext) => {
- expected = `${isValid},${newNumber},${countryData.iso2},${fullNumber},${ext}`;
+ const onPhoneNumberChange = (
+ isValid,
+ newNumber,
+ countryData,
+ fullNumber,
+ ext
+ ) => {
+ expected = `${isValid},${newNumber},${
+ countryData.iso2
+ },${fullNumber},${ext}`;
};
this.params.onPhoneNumberChange = onPhoneNumberChange;
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('change', { target: { value: '+886911222333' } });
@@ -271,17 +299,27 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('onPhoneNumberBlur', () => {
let expected = '';
- const onPhoneNumberBlur = (isValid, newNumber, countryData, fullNumber, ext) => {
- expected = `${isValid},${newNumber},${countryData.iso2},${fullNumber},${ext}`;
+ const onPhoneNumberBlur = (
+ isValid,
+ newNumber,
+ countryData,
+ fullNumber,
+ ext
+ ) => {
+ expected = `${isValid},${newNumber},${
+ countryData.iso2
+ },${fullNumber},${ext}`;
};
this.params.onPhoneNumberBlur = onPhoneNumberBlur;
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('change', { target: { value: '+886911222333' } });
@@ -320,9 +358,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('isValidNumber', () => {
const subject = this.makeSubject();
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
expect(subject.instance().isValidNumber('0910123456')).toBeTruthy();
@@ -337,9 +377,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
inputComponent.simulate('change', { target: { value: '910123456' } });
@@ -351,9 +393,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
expect(inputComponent.props().placeholder).toBe('foo');
@@ -482,9 +526,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('should change input placeholder on customPlaceholder prop change', () => {
const subject = this.makeSubject();
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
subject.setProps({ customPlaceholder: () => 'Phone number' });
@@ -505,7 +551,9 @@ describe('TelInput', function () { // eslint-disable-line func-names
flagComponent.simulate('click');
expect(subject.instance().wrapperClass.expanded).toBe(true);
- const taiwanOption = subject.find(FlagDropDown).find('[data-country-code="tw"]');
+ const taiwanOption = subject
+ .find(FlagDropDown)
+ .find('[data-country-code="tw"]');
taiwanOption.simulate('click');
expect(subject.instance().wrapperClass.expanded).toBe(false);
@@ -538,9 +586,11 @@ describe('TelInput', function () { // eslint-disable-line func-names
it('should change props value', () => {
const subject = this.makeSubject();
- requests[0].respond(200,
+ requests[0].respond(
+ 200,
{ 'Content-Type': 'text/javascript' },
- libphonenumberUtils);
+ libphonenumberUtils
+ );
window.eval(getScript().text);
subject.setState({
diff --git a/src/components/__tests__/utils.test.js b/src/components/__tests__/utils.test.js
index d03e6275a..19e78ab9f 100644
--- a/src/components/__tests__/utils.test.js
+++ b/src/components/__tests__/utils.test.js
@@ -117,10 +117,21 @@ describe('utils', () => {
areaCodes: null,
};
- expect(utils.getCountryData(AllCountries.getCountries(), 'tw')).toEqual(result);
- expect(utils.getCountryData(AllCountries.getCountries(), 'zz', true, true)).toBeNull();
- expect(utils.getCountryData(AllCountries.getCountries(),
- 'zz', false, false, (country) => `${country}!!`)).toEqual({});
+ expect(utils.getCountryData(AllCountries.getCountries(), 'tw')).toEqual(
+ result
+ );
+ expect(
+ utils.getCountryData(AllCountries.getCountries(), 'zz', true, true)
+ ).toBeNull();
+ expect(
+ utils.getCountryData(
+ AllCountries.getCountries(),
+ 'zz',
+ false,
+ false,
+ country => `${country}!!`
+ )
+ ).toEqual({});
});
it('hasClass', () => {
@@ -164,12 +175,12 @@ describe('utils', () => {
expect(utils.findIndex(array, predicate)).toEqual(-1);
array = [1, 2, 3];
- predicate = (item) => item === 2;
+ predicate = item => item === 2;
expect(utils.findIndex(array, predicate)).toEqual(1);
array = [1, 2, 3];
- predicate = (item) => item === 4;
+ predicate = item => item === 4;
expect(utils.findIndex(array, predicate)).toEqual(-1);
});
@@ -179,24 +190,48 @@ describe('utils', () => {
let previousString = '912345';
let nextString = '912345';
- expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(4);
+ expect(
+ utils.getCursorPositionAfterFormating(
+ previousStringBeforeCursor,
+ previousString,
+ nextString
+ )
+ ).toEqual(4);
previousStringBeforeCursor = '0912 345';
previousString = '0912 345 678';
nextString = '91234678';
- expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(5);
+ expect(
+ utils.getCursorPositionAfterFormating(
+ previousStringBeforeCursor,
+ previousString,
+ nextString
+ )
+ ).toEqual(5);
previousStringBeforeCursor = '91234';
previousString = '91234678';
nextString = '0912 345 678';
- expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(7);
+ expect(
+ utils.getCursorPositionAfterFormating(
+ previousStringBeforeCursor,
+ previousString,
+ nextString
+ )
+ ).toEqual(7);
previousStringBeforeCursor = '(201) 5';
previousString = '(201) 55-01';
nextString = '201-5501';
- expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(5);
+ expect(
+ utils.getCursorPositionAfterFormating(
+ previousStringBeforeCursor,
+ previousString,
+ nextString
+ )
+ ).toEqual(5);
});
});
diff --git a/src/example.js b/src/example.js
index abbd9f9b5..09e5202d8 100644
--- a/src/example.js
+++ b/src/example.js
@@ -86,7 +86,7 @@ class DemoComponent extends Component {
format
/>
-Phone Number:
+ Phone Number:
{this.state.phone1}
@@ -99,7 +99,7 @@ Phone Number:
css={['intl-tel-input', 'form-control']}
/>
-Phone Number:
+ Phone Number:
{this.state.phone2}