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/