Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An element's child nodes will be gone under certain circumstances in IE (at least 7 & 8) #13

Closed
timmolendijk opened this issue Mar 11, 2010 · 3 comments

Comments

@timmolendijk
Copy link

Consider a test page with a main section as follows:

<div id="main">
    <ul>
        <li>yadda</li>
    </ul>
</div>

And a test script as follows:

jQuery(function($) {
    var $elem = $('#main > ul');
    console.log($elem.children().length);
    module('blub');
    test('yadda', function() {
        console.log($elem.children().length);
});
});

One would expect that this prints two times 1 to the console, which it does in Firefox and Chrome. In Internet Explorer (I've tested 7 & 8) it will print 1 and then 0 though, indicating that the element has somehow been emptied somewhere during starting up test yadda. If I reinforce $elem by putting $elem = $('#main > ul'); in a module setup function, the problem miraculously disappears.

@jzaefferer
Copy link
Member

Elements inside the #main element get reset after each test run. The inconsistency across browsers is odd, but fine, as you should rely on any selection that ran outside your current test.

@timmolendijk
Copy link
Author

Did you mean "(...) as you should not rely on any selection that ran outside your current test" ?

Okay, that's a workable restriction. But I wasn't aware of it. How is one supposed to learn about it?

@jzaefferer
Copy link
Member

Yeah, meant what you wrote.

I need to backport some of the documentation from the jQuery Cookbook chapter on testing to the QUnit documentation.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants