jquery - Zombie Js jQuery null TypeError 'compareDocumentPosition'

标签 jquery jsdom zombie.js

zombie :无法读取 null 的属性“compareDocumentPosition” TypeError:无法读取属性“compareDocumentPosition” 为空

每当我尝试使用 Zombiejs 加载包含 jQuery 的页面时,都会发生这种情况。我在 Debian 和 Windows 上就遇到过这种情况,有各种不同的页面,使用不同版本的 jQuery,页面上没有其他内容。

这似乎与 jsDom 在页面文档准备好之前评估 jQuery 的方式有关,但这远远超出了我的理解范围。

有人遇到过这个问题,知道解决方法,或者有任何指示吗?谢谢!

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

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

这会导致其他错误,因为我的其余脚本中未定义“$”。

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

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

最佳答案

这是在黑暗中拍摄的,但我克隆了 https://github.com/assaf/zombie.git并 grep 查找compareDocumentPosition。文件中找到的第一行如下所示:

if ( document.documentElement.compareDocumentPosition ) {

现在,document.documentElement 通常指向 <html> -tag,你可能错过了吗?

关于jquery - Zombie Js jQuery null TypeError 'compareDocumentPosition',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9370771/

相关文章:

javascript - 如何从中心开始设置 div 的动画

javascript - 如何让HTML的title属性停留更长时间

javascript - Node.js 似乎在循环后没有释放内存

javascript - Zombie.js jQuery 加载错误 'j.getClientRects is not a function'

javascript - JQuery - 停止 Accordion 链接关闭所有选项卡

jquery - 如何应用具有关键帧动画的 CSS3 变换?

unit-testing - 如何使用 JSDom 对 Jest 中的自定义元素执行单元测试

javascript - 以编程方式触发 jsdom 窗口中的滚动或按键事件

javascript - 将 javascript 注入(inject) zombie.js

node.js - 如何使用 zombie.js 登录 Wordpress 管理员?