Zombiejs jQuery nullTypeError 'compareDocument

2019-08-12 06:45发布

Zombie: Cannot read property 'compareDocumentPosition' of null TypeError: Cannot read property 'compareDocumentPosition' of null

This happens any time I try to load a page that includes jQuery using Zombiejs. This has happened to me on Debian & Windows, with a variety of different pages, using different versions of jQuery and with nothing else on the page.

It seems to have something to do with the way jsDom evaluates jQuery before the page document is ready, but it's pretty far over my head.

Anyone run into this, know a workaround, or have any pointers? Thanks!

UPDATE: This is my test (which actually passes, but running with debug shows the error I mentioned):

zombie = require "zombie"
browser = new zombie.Browser({debug: false})
$ = require "jquery"
require "should"    

app = "http://localhost:3000/"

describe "app", ->
  describe "index", ->
    it "should display correct title", (done) ->
      browser.visit app, (err, browser) ->
        done()

And this is the error:

Zombie: GET http://localhost:3000/js/jquery-1.7.1.js => 200 Zombie: Cannot read property 'compareDocumentPosition' of null TypeError: Cannot read property 'compareDocumentPosition' of null
    at Object.<anonymous> (/js/jquery-1.7.1.js:4807:30)
    at Object.<anonymous> (/js/jquery-1.7.1.js:5301:2)
    at Object.<anonymous> (/js/jquery-1.7.1.js:9266:2)
    at Object._evaluate (/home/dev/Hg/rpg-chat-bdd/node_modules/zombie/lib/zombie/browser.js:136:28)
    in /js/jquery-1.7.1.js

which causes a other errors because '$' is not defined in the rest of my scripts.

This is the HTML of the page I'm testing:

<title>Welcome to Test!</title>

<body>
  <div id="main">
  </div>

  <script type="text/javascript" src="/js/jquery-1.7.1.js"></script>
  <script type="text/javascript" src="/js/application.js"></script>
</body>

1条回答
SAY GOODBYE
2楼-- · 2019-08-12 07:30

this is a shot in the dark, but i cloned https://github.com/assaf/zombie.git and grepped for compareDocumentPosition. The first line(s) found in the files are like this:

if ( document.documentElement.compareDocumentPosition ) {

Now, document.documentElement usually points to the <html>-tag, are you maybe missing that?

查看更多
登录 后发表回答