Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
test(jqLite): make iframe contents() test less flaky
Closes #8157
  • Loading branch information
caitp committed Jul 16, 2014
1 parent 3c7f0f7 commit d7b3aa9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
7 changes: 1 addition & 6 deletions karma-jqlite.conf.js
Expand Up @@ -7,12 +7,7 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});

config.set({
files: angularFiles.mergeFilesFor('karma').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
files: angularFiles.mergeFilesFor('karma'),
exclude: angularFiles.mergeFilesFor('karmaExclude'),

junitReporter: {
Expand Down
7 changes: 1 addition & 6 deletions karma-jquery.conf.js
Expand Up @@ -7,12 +7,7 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaJquery').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
files: angularFiles.mergeFilesFor('karmaJquery'),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
Expand Down
9 changes: 0 additions & 9 deletions test/fixtures/iframe.html

This file was deleted.

55 changes: 30 additions & 25 deletions test/jqLiteSpec.js
Expand Up @@ -1444,32 +1444,37 @@ describe('jqLite', function() {
expect(contents[1].data).toEqual('before-');
});

// IE8 does not like this test, although the functionality may still work there.
if (!msie || msie > 8) {
it('should select all types iframe contents', function() {
var iframe_ = document.createElement('iframe'), tested,
iframe = jqLite(iframe_);
function test() {
var contents = iframe.contents();
expect(contents[0]).toBeTruthy();
expect(contents.length).toBe(1);
expect(contents.prop('nodeType')).toBe(9);
expect(contents[0].body).toBeTruthy();
expect(jqLite(contents[0].body).contents().length).toBe(3);
iframe.remove();
tested = true;
}
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument) test();
};
iframe_.src = "/base/test/fixtures/iframe.html";
jqLite(document).find('body').append(iframe);
it('should select all types iframe contents', function() {
// IE8 does not like this test, although the functionality may still work there.
if (msie < 9) return;
var iframe_ = document.createElement('iframe');
var tested = false;
var iframe = jqLite(iframe_);
function test() {
var doc = iframe_.contentDocument || iframe_.contentWindow.document;
doc.body.innerHTML = '\n<span>Text</span>\n';

var contents = iframe.contents();
expect(contents[0]).toBeTruthy();
expect(contents.length).toBe(1);
expect(contents.prop('nodeType')).toBe(9);
expect(contents[0].body).toBeTruthy();
expect(jqLite(contents[0].body).contents().length).toBe(3);
iframe.remove();
doc = null;
tested = true;
}
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument) test();
};
/* jshint scripturl:true */
iframe_.src = 'javascript:false';
jqLite(document).find('body').append(iframe);

// This test is potentially flaky on CI cloud instances, so there is a generous
// wait period...
waitsFor(function() { return tested; }, 'iframe to load', 5000);
});
}
// This test is potentially flaky on CI cloud instances, so there is a generous
// wait period...
waitsFor(function() { return tested; }, 'iframe to load', 5000);
});
});


Expand Down

0 comments on commit d7b3aa9

Please sign in to comment.