Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d7b3aa9

Browse files
committed
test(jqLite): make iframe contents() test less flaky
Closes #8157
1 parent 3c7f0f7 commit d7b3aa9

File tree

4 files changed

+32
-46
lines changed

4 files changed

+32
-46
lines changed

karma-jqlite.conf.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ module.exports = function(config) {
77
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});
88

99
config.set({
10-
files: angularFiles.mergeFilesFor('karma').concat({
11-
pattern: "test/fixtures/**/*.html",
12-
served: true,
13-
watched: true,
14-
included: false
15-
}),
10+
files: angularFiles.mergeFilesFor('karma'),
1611
exclude: angularFiles.mergeFilesFor('karmaExclude'),
1712

1813
junitReporter: {

karma-jquery.conf.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ module.exports = function(config) {
77
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});
88

99
config.set({
10-
files: angularFiles.mergeFilesFor('karmaJquery').concat({
11-
pattern: "test/fixtures/**/*.html",
12-
served: true,
13-
watched: true,
14-
included: false
15-
}),
10+
files: angularFiles.mergeFilesFor('karmaJquery'),
1611
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
1712

1813
junitReporter: {

test/fixtures/iframe.html

-9
This file was deleted.

test/jqLiteSpec.js

+30-25
Original file line numberDiff line numberDiff line change
@@ -1444,32 +1444,37 @@ describe('jqLite', function() {
14441444
expect(contents[1].data).toEqual('before-');
14451445
});
14461446

1447-
// IE8 does not like this test, although the functionality may still work there.
1448-
if (!msie || msie > 8) {
1449-
it('should select all types iframe contents', function() {
1450-
var iframe_ = document.createElement('iframe'), tested,
1451-
iframe = jqLite(iframe_);
1452-
function test() {
1453-
var contents = iframe.contents();
1454-
expect(contents[0]).toBeTruthy();
1455-
expect(contents.length).toBe(1);
1456-
expect(contents.prop('nodeType')).toBe(9);
1457-
expect(contents[0].body).toBeTruthy();
1458-
expect(jqLite(contents[0].body).contents().length).toBe(3);
1459-
iframe.remove();
1460-
tested = true;
1461-
}
1462-
iframe_.onload = iframe_.onreadystatechange = function() {
1463-
if (iframe_.contentDocument) test();
1464-
};
1465-
iframe_.src = "/base/test/fixtures/iframe.html";
1466-
jqLite(document).find('body').append(iframe);
1447+
it('should select all types iframe contents', function() {
1448+
// IE8 does not like this test, although the functionality may still work there.
1449+
if (msie < 9) return;
1450+
var iframe_ = document.createElement('iframe');
1451+
var tested = false;
1452+
var iframe = jqLite(iframe_);
1453+
function test() {
1454+
var doc = iframe_.contentDocument || iframe_.contentWindow.document;
1455+
doc.body.innerHTML = '\n<span>Text</span>\n';
1456+
1457+
var contents = iframe.contents();
1458+
expect(contents[0]).toBeTruthy();
1459+
expect(contents.length).toBe(1);
1460+
expect(contents.prop('nodeType')).toBe(9);
1461+
expect(contents[0].body).toBeTruthy();
1462+
expect(jqLite(contents[0].body).contents().length).toBe(3);
1463+
iframe.remove();
1464+
doc = null;
1465+
tested = true;
1466+
}
1467+
iframe_.onload = iframe_.onreadystatechange = function() {
1468+
if (iframe_.contentDocument) test();
1469+
};
1470+
/* jshint scripturl:true */
1471+
iframe_.src = 'javascript:false';
1472+
jqLite(document).find('body').append(iframe);
14671473

1468-
// This test is potentially flaky on CI cloud instances, so there is a generous
1469-
// wait period...
1470-
waitsFor(function() { return tested; }, 'iframe to load', 5000);
1471-
});
1472-
}
1474+
// This test is potentially flaky on CI cloud instances, so there is a generous
1475+
// wait period...
1476+
waitsFor(function() { return tested; }, 'iframe to load', 5000);
1477+
});
14731478
});
14741479

14751480

0 commit comments

Comments
 (0)