Skip to content

Commit

Permalink
get tests passing on IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Sep 23, 2018
1 parent 81ae923 commit db918c3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 28 deletions.
4 changes: 3 additions & 1 deletion grunt/jasmine.js
Expand Up @@ -8,7 +8,9 @@ module.exports = function(grunt) {
options: {
vendor: [
'node_modules/jquery/dist/jquery.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
'node_modules/es6-promise/dist/es6-promise.auto.js', // for IE11
'node_modules/custom-event-polyfill/polyfill.js', // for IE11
],
helpers: [
'src/spec/helpers/**/*.js'
Expand Down
14 changes: 10 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -16,6 +16,8 @@
"license": "MIT",
"author": "Jack O'Connor (http://jackocnr.com)",
"devDependencies": {
"custom-event-polyfill": "^1.0.6",
"es6-promise": "^4.2.5",
"evenizer": "^0.1.17",
"grunt": "^1.0.1",
"grunt-bump": "^0.8.0",
Expand Down
4 changes: 4 additions & 0 deletions spec.html
Expand Up @@ -26,6 +26,10 @@

<script src="node_modules/jasmine-jquery/lib/jasmine-jquery.js"></script>

<script src="node_modules/es6-promise/dist/es6-promise.auto.js"></script>

<script src="node_modules/custom-event-polyfill/polyfill.js"></script>

<script src="src/spec/helpers/helpers.js"></script>

<script src="src/js/data.js"></script>
Expand Down
25 changes: 13 additions & 12 deletions src/spec/helpers/helpers.js
Expand Up @@ -97,7 +97,7 @@ var selectFlag = function(countryCode, i) {
};

var openCountryDropDown = function() {
getSelectedFlagContainer()[0].click();
getSelectedFlagContainer()[0].click();
};

var putCursorAtEnd = function() {
Expand All @@ -109,23 +109,24 @@ var selectInputChars = function(start, end) {
input[0].setSelectionRange(start, end);
};

// use this for focus/blur (instead of using .focus() and .blur() directly, which cause problems in IE11)
var triggerInputEvent = function(type) {
var e = new CustomEvent(type);
input[0].dispatchEvent(e);
}

var triggerKey = function(el, type, key) {
var event = new KeyboardEvent(type, { key: key });
el.dispatchEvent(event);
return event;
var e = new CustomEvent(type);
e.key = key;
el.dispatchEvent(e);
};

// trigger keydown, then keypress, then add the key, then keyup
var triggerKeyOnInput = function(key) {
triggerKey(input[0], 'keydown', key);
var e = triggerKey(input[0], 'keypress', key);
// insert char
if (!e.defaultPrevented) {
var val = input.val(),
before = val.substr(0, input[0].selectionStart),
after = val.substring(input[0].selectionEnd, val.length);
input.val(before + key + after);
}
triggerKey(input[0], 'keypress', key);
var val = input.val();
input.val(val + key);
triggerKey(input[0], 'keyup', key);
};

Expand Down
16 changes: 8 additions & 8 deletions src/spec/tests/options/autoHideDialCode.js
Expand Up @@ -32,7 +32,7 @@ describe("autoHideDialCode option:", function() {
describe("focusing the input", function() {

beforeEach(function() {
input[0].focus();
triggerInputEvent("focus");
});

it("adds the default dial code", function() {
Expand All @@ -48,7 +48,7 @@ describe("autoHideDialCode option:", function() {
});

it("blurring it removes it again", function() {
input[0].blur();
triggerInputEvent("blur");
expect(getInputVal()).toEqual("");
});

Expand All @@ -65,9 +65,9 @@ describe("autoHideDialCode option:", function() {
});

it("focusing and blurring the input doesn't change it", function() {
input[0].focus();
triggerInputEvent("focus");
expect(getInputVal()).toEqual(number);
input[0].blur();
triggerInputEvent("blur");
expect(getInputVal()).toEqual(number);
});

Expand All @@ -90,9 +90,9 @@ describe("autoHideDialCode option:", function() {
});

it("focusing and bluring the input dont change the val", function() {
input[0].focus();
triggerInputEvent("focus");
expect(getInputVal()).toEqual(defaultDialCode);
input[0].blur();
triggerInputEvent("blur");
expect(getInputVal()).toEqual(defaultDialCode);
});

Expand All @@ -106,9 +106,9 @@ describe("autoHideDialCode option:", function() {
});

it("focusing and blurring the input doesn't change it", function() {
input[0].focus();
triggerInputEvent("focus");
expect(getInputVal()).toEqual(number);
input[0].blur();
triggerInputEvent("blur");
expect(getInputVal()).toEqual(number);
});

Expand Down
2 changes: 1 addition & 1 deletion src/spec/tests/options/geoIpLookup.js
Expand Up @@ -57,8 +57,8 @@ describe("geoIpLookup:", function() {
});
iti.promise.then(function() {
resolved = true;
done();
});
setTimeout(done);
});

it("does resolve", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/spec/tests/options/nationalMode.js
Expand Up @@ -28,7 +28,7 @@ describe("nationalMode:", function() {
});

it("focusing the input does not insert the dial code", function() {
input.focus();
triggerInputEvent("focus");
expect(getInputVal()).toEqual("");
});

Expand Down
2 changes: 1 addition & 1 deletion src/spec/tests/options/onlyCountries.js
Expand Up @@ -84,7 +84,7 @@ describe("onlyCountries option:", function() {
});

it("first instance still works", function() {
input.focus();
triggerInputEvent("focus");
expect(input.val()).toEqual("+81");
});

Expand Down

0 comments on commit db918c3

Please sign in to comment.