Zombiejs jQuery nullTypeError 'compareDocumentPosition'

依然范特西╮ 提交于 2020-02-25 09:21:30

问题


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:


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?



来源:https://stackoverflow.com/questions/9370771/zombiejs-jquery-nulltypeerror-comparedocumentposition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!