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

$(document).ready(fn) does not fire (jquery compatibility problem) #3

Closed
GoogleCodeExporter opened this issue Aug 3, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. create a tmp folder, copy in jquery-1.3.1.js
2. create a file named test_docready.js that looks like:

TestCase("TestDocready", {

    test_docready: function() {
        expectAsserts(1);
        var counter = 0;
        $(document).ready(function(){
            counter += 1;
        });
        $(document).ready(function(){
            assertEquals(counter, 1);
        });
    }

});

3. create a conf that looks like:

server: http://localhost:4224

load:
    - jquery*.js
    - test*.js

4. start the server as normal : java -jar ~/src/JsTestDriver-1.0b.jar
--port 4224 --captureConsole 
5. Open some browsers to http://127.0.0.1:4224/capture
6. Run the tests as you would normally: java -jar
~/src/JsTestDriver-1.0b.jar --tests all 

What is the expected output? What do you see instead?

I'd think that $(document).ready(fn) would fire like normal but instead the
tests fail, indicating that ready(fn) never fires:

FF
Total 2 tests (Passed: 0; Fails: 2; Errors: 0) (2.00 ms)
  Safari 525.28.3: Run 1 tests (Passed: 0; Fails: 1; Errors 0) (0.00 ms)
    TestDocready.test_docready failed (0.00 ms): Expected '1' asserts but
'0' encountered.
  Firefox 1.9.0.10: Run 1 tests (Passed: 0; Fails: 1; Errors 0) (2.00 ms)
    TestDocready.test_docready failed (2.00 ms): Expected '1' asserts but
'0' encountered.

*However* if I swap out jquery-1.3.1.js for jquery-1.2.6.js then the test
passes in Safari only:

.F
Total 2 tests (Passed: 1; Fails: 1; Errors: 0) (1.00 ms)
  Safari 525.28.3: Run 1 tests (Passed: 1; Fails: 0; Errors 0) (1.00 ms)
  Firefox 1.9.0.10: Run 1 tests (Passed: 0; Fails: 1; Errors 0) (1.00 ms)
    TestDocready.test_docready failed (1.00 ms): Expected '1' asserts but
'0' encountered.

What version of the product are you using? On what operating system?


Please provide any additional information below.

If you know of a workaround (maybe manually triggering jquery's ready
functions?) then let me know because I can't think of another way to use
js-test-driver to test jquery code.

Original issue reported on code.google.com by kumar.mcmillan on 27 May 2009 at 2:36

@GoogleCodeExporter
Copy link
Author

Hi Kumar,

We already load jquery, could you try the same test without loading your own 
version
of jquery?

Also, we are not reloading the document every time, we only reload the 
javascript
that changed so this event will not be fired. Why not call your callback 
directly
from your test?

Let me know if it helps.

Thanks !

Original comment by toc...@gmail.com on 27 May 2009 at 10:51

@GoogleCodeExporter
Copy link
Author

Aha, removing the line in my conf that was loading jquery did indeed fix the 
problem.
 Thanks!  You may want to add this to the docs and also note the version of jquery
that will be preloaded.

By the way, the test above passes every time.  In other words, your reload code
preserves the functionality of calling $(document).ready(fn).

Why not call my callback directly?  There are a few reasons.  One is that I was
actually trying to test an initialization function that will wrap the input in
$(document).ready() based on some conditions.  And the other is that a lot of
configuration code is wrapped in anonymous functions because so much of it must 
run
only at ready() time.


Original comment by kumar.mcmillan on 28 May 2009 at 12:43

@GoogleCodeExporter
Copy link
Author

Great !

I will definitely add the fact that we preload jQuery (and the version number) 
into our documentation.

Thanks !


Original comment by toc...@gmail.com on 28 May 2009 at 2:12

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant