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

Commit af5aacc

Browse files
committed
test(jqLite): make iframe contents() test less flaky
1 parent 3abd0fb commit af5aacc

File tree

4 files changed

+32
-46
lines changed

4 files changed

+32
-46
lines changed

karma-jqlite.conf.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ module.exports = function(config) {
55
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});
66

77
config.set({
8-
files: angularFiles.mergeFilesFor('karma').concat({
9-
pattern: "test/fixtures/**/*.html",
10-
served: true,
11-
watched: true,
12-
included: false
13-
}),
8+
files: angularFiles.mergeFilesFor('karma'),
149
exclude: angularFiles.mergeFilesFor('karmaExclude'),
1510

1611
junitReporter: {

karma-jquery.conf.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ module.exports = function(config) {
55
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});
66

77
config.set({
8-
files: angularFiles.mergeFilesFor('karmaJquery').concat({
9-
pattern: "test/fixtures/**/*.html",
10-
served: true,
11-
watched: true,
12-
included: false
13-
}),
8+
files: angularFiles.mergeFilesFor('karmaJquery'),
149
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
1510

1611
junitReporter: {

test/fixtures/iframe.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/jqLiteSpec.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,32 +1397,37 @@ describe('jqLite', function() {
13971397
expect(contents[1].data).toEqual('before-');
13981398
});
13991399

1400-
// IE8 does not like this test, although the functionality may still work there.
1401-
if (!msie || msie > 8) {
1402-
it('should select all types iframe contents', function() {
1403-
var iframe_ = document.createElement('iframe'), tested,
1404-
iframe = jqLite(iframe_);
1405-
function test() {
1406-
var contents = iframe.contents();
1407-
expect(contents[0]).toBeTruthy();
1408-
expect(contents.length).toBe(1);
1409-
expect(contents.prop('nodeType')).toBe(9);
1410-
expect(contents[0].body).toBeTruthy();
1411-
expect(jqLite(contents[0].body).contents().length).toBe(3);
1412-
iframe.remove();
1413-
tested = true;
1414-
}
1415-
iframe_.onload = iframe_.onreadystatechange = function() {
1416-
if (iframe_.contentDocument) test();
1417-
};
1418-
iframe_.src = "/base/test/fixtures/iframe.html";
1419-
jqLite(document).find('body').append(iframe);
1400+
it('should select all types iframe contents', function() {
1401+
// IE8 does not like this test, although the functionality may still work there.
1402+
if (msie < 9) return;
1403+
var iframe_ = document.createElement('iframe');
1404+
var tested = false;
1405+
var iframe = jqLite(iframe_);
1406+
function test() {
1407+
var doc = iframe_.contentDocument || iframe_.contentWindow.document;
1408+
doc.body.innerHTML = '\n<span>Text</span>\n';
1409+
1410+
var contents = iframe.contents();
1411+
expect(contents[0]).toBeTruthy();
1412+
expect(contents.length).toBe(1);
1413+
expect(contents.prop('nodeType')).toBe(9);
1414+
expect(contents[0].body).toBeTruthy();
1415+
expect(jqLite(contents[0].body).contents().length).toBe(3);
1416+
iframe.remove();
1417+
doc = null;
1418+
tested = true;
1419+
}
1420+
iframe_.onload = iframe_.onreadystatechange = function() {
1421+
if (iframe_.contentDocument) test();
1422+
};
1423+
/* jshint scripturl:true */
1424+
iframe_.src = 'javascript:false';
1425+
jqLite(document).find('body').append(iframe);
14201426

1421-
// This test is potentially flaky on CI cloud instances, so there is a generous
1422-
// wait period...
1423-
waitsFor(function() { return tested; }, 2000);
1424-
});
1425-
}
1427+
// This test is potentially flaky on CI cloud instances, so there is a generous
1428+
// wait period...
1429+
waitsFor(function() { return tested; }, 5000);
1430+
});
14261431
});
14271432

14281433

0 commit comments

Comments
 (0)