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

Zombie.js jQuery Load Error 'j.getClientRects is not a function'

首先我阅读了 this Stack Overflow 问题,它看起来不像我的问题。

基本上,我正在尝试使用 Mocha 和 Zombie.js 在我的 Node.js 网站上 运行 进行一些测试。

我正在尝试检查是否可以创建用户。最后我想检查一下我的 bootstrap 模式是否存在。基本上,我将 bootstrap 模式封装在 EJS if 语句中,因此它很可能不存在。所以这就是我尝试 运行 对其进行测试的原因。

但目前它甚至不能与 browser.assert.success(); 一起使用,所以我目前只是想在继续检查元素之前解决这个问题。

browser.visit('/login', function() {
    browser.fill('email', 'test1@test.com');
    browser.fill('password', 'testtest');
    browser.pressButton('Login').then(function() {
        browser.assert.success();
    }).then(done, done);
});

在这种情况下,我应该运行在浏览器当前所在的页面上添加以下代码。

<script>
    $("#paymentModal").modal('show');
</script>

当 运行 进行此单元测试时,出现以下错误。

https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3
}return c}function Q(a){var b;for(b in a)if(("data"!==b||!n.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function R(a,b,d,e){if(M(a)){var f,g,h=n.expando,i=a.nodeType,j=i?n.cache:a,k=i?a[h]:a[h]&&h;if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||n.guid++:h),j[k]||(j[k]=i?{}:{toJSON:n.noop}),"object"!=typeof b&&"function"!=typeof b||(e?j[k]=n.extend(j[k],b):j[k].data=n.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[n.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[n.camelCase(b)])):f=g,f}}function S(a,b,c){if(M(a)){var d,e,f=a.nodeType,g=f?n.cache:a,h=f?a[n.expando]:n.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){n.isArray(b)?b=b.concat(n.map(b,n.camelCase)):b in d?b=[b]:(b=n.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!Q(d):!n.isEmptyObject(d))return}(c||(delete g[h].data,Q(g[h])))&&(f?n.cleanData([a],!0):l.deleteExpan
TypeError: j.getClientRects is not a function
 at k (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:26891)
 at Object.n.extend.pixelMarginRight (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:25936)
 at a.getComputedStyle.Sa (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:27592)
 at Function.n.extend.css (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:30895)
 at https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:4:520
 at Y (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:3:4661)
 at n.fn.extend.css (https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js:4:361)
 at c.setScrollbar (http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js:6:18612)
 at c.show (http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js:6:14692)
 at .<anonymous> (http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js:6:13878)

在我看来,由于某种原因 Zombie.js 未在该页面上加载 jQuery,或者存在错误。但是在之前的 Stack Overflow 问题和问题开头的答案中,Zombie.js 可以加载 jQuery.

您无法用 Zombie.js 加载 jQuery 吗?我怎样才能解决这个问题?使用 jQuery 测试页面似乎是一件非常简单的事情。有什么想法吗?

如果您需要任何其他信息或任何其他信息,请告诉我。谢谢。

EDIT 出于某种原因,当降级到 jQuery 版本 1.11.3 时,它似乎可以工作并且错误消失了。有什么原因吗?

此错误已修复:https://github.com/assaf/zombie/issues/1031

Adopting jsdom 8/9 as the fix for your problem was harder than I wanted. It should be pretty easy to add a dummy implementation for getClientRects() just to get past that specific failure. I'll try that and see how it goes

Add a stub implementation of getClientRects() was straightforward. I've published 5.0.1 with a fix for this specific failure.

mdlavin