Zombiejs jQuery nullTypeError'compareDocumentPosition' [英] Zombiejs jQuery nullTypeError 'compareDocumentPosition'

查看:154
本文介绍了Zombiejs jQuery nullTypeError'compareDocumentPosition'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

僵尸:无法读取null类型的属性'compareDocumentPosition'错误:无法读取属性'compareDocumentPosition' 为空

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

每当我尝试使用Zombiejs加载包含jQuery的页面时,都会发生这种情况.这发生在Debian& amp; Windows,具有各种不同的页面,使用不同版本的jQuery,并且页面上没有其他内容.

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.

这似乎与jsDom在页面文档准备好之前评估jQuery的方式有关,但是这远远超出了我的脑海.

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!

更新:这是我的测试(实际上通过了,但是运行debug会显示我提到的错误):

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()

这是错误:

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.

这是我正在测试的页面的HTML:

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>

推荐答案

这是黑暗中的一枪,但我克隆了

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 ) {

现在,document.documentElement通常指向<html>-标记,您可能会丢失它吗?

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

这篇关于Zombiejs jQuery nullTypeError'compareDocumentPosition'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆