Skip to content

Commit

Permalink
Unit test of formatNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
patw0929 committed Feb 27, 2017
1 parent 78e211d commit 0830646
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion __tests__/FlagDropDown.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable react/no-find-dom-node */
/* eslint-disable react/no-find-dom-node, no-eval */
import React from 'react';
import ReactDOM from 'react-dom';
import { mount } from 'enzyme';
Expand All @@ -13,6 +13,7 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
let libphonenumberUtils;
let xhr;
let requests;
let getScript;

beforeEach(() => {
jest.resetModules();
Expand All @@ -23,6 +24,9 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
xhr.onCreate = (req) => { requests.push(req); };
window.intlTelInputUtils = undefined;

getScript = () =>
document.getElementsByTagName('script')[0];

this.params = {
css: ['intl-tel-input', 'form-control phoneNumber'],
fieldName: 'telephone',
Expand Down Expand Up @@ -458,4 +462,17 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
areaCodes: null,
});
});

it('should output formatted number with formatNumber function', () => {
this.params.format = true;
this.params.nationalMode = true;
const subject = this.makeSubject();

requests[0].respond(200,
{ 'Content-Type': 'text/javascript' },
libphonenumberUtils);
window.eval(getScript().text);

expect(subject.instance().formatNumber('+886 912 345 678')).toBe('0912 345 678');
});
});

0 comments on commit 0830646

Please sign in to comment.