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

Commit 05fbed5

Browse files
committed
fix(jqLite): make jqLite('<iframe src="someurl">').contents() return iframe document, as in jQuery
This is a very tiny change to make behaviour consistent with jQuery. Closes #6320 Closes #6323
1 parent 21dac2a commit 05fbed5

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

karma-jqlite.conf.js

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

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

1116
junitReporter: {

karma-jquery.conf.js

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

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

1116
junitReporter: {

src/jqLite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ forEach({
793793
},
794794

795795
contents: function(element) {
796-
return element.childNodes || [];
796+
return element.contentDocument || element.childNodes || [];
797797
},
798798

799799
append: function(element, node) {

test/fixtures/iframe.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Iframe Test</title>
5+
</head>
6+
<body>
7+
<span>Text</span>
8+
</body>
9+
</html>

test/jqLiteSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,33 @@ describe('jqLite', function() {
12991299
expect(contents[0].data).toEqual(' some comment ');
13001300
expect(contents[1].data).toEqual('before-');
13011301
});
1302+
1303+
// IE8 does not like this test, although the functionality may still work there.
1304+
if (!msie || msie > 8) {
1305+
it('should select all types iframe contents', function() {
1306+
var iframe_ = document.createElement('iframe'), tested,
1307+
iframe = jqLite(iframe_);
1308+
function test() {
1309+
var contents = iframe.contents();
1310+
expect(contents[0]).toBeTruthy();
1311+
expect(contents.length).toBe(1);
1312+
expect(contents.prop('nodeType')).toBe(9);
1313+
expect(contents[0].body).toBeTruthy();
1314+
expect(jqLite(contents[0].body).contents().length).toBe(3);
1315+
iframe.remove();
1316+
tested = true;
1317+
}
1318+
iframe_.onload = iframe_.onreadystatechange = function() {
1319+
if (iframe_.contentDocument) test();
1320+
};
1321+
iframe_.src = "/base/test/fixtures/iframe.html";
1322+
jqLite(document).find('body').append(iframe);
1323+
1324+
// This test is potentially flaky on CI cloud instances, so there is a generous
1325+
// wait period...
1326+
waitsFor(function() { return tested; }, 2000);
1327+
});
1328+
}
13021329
});
13031330

13041331

0 commit comments

Comments
 (0)