Zombie.js jQuery加载错误'j.getClientRects不是一个函数'

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

本文关键字:函数 一个 jQuery js 加载 错误 Zombie getClientRects      更新时间:2023-09-26

所以首先我读了这个堆栈溢出问题,它看起来不像我的问题。

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

我正在尝试检查是否可以创建用户。最后,我想检查一下我的引导模式是否存在。基本上,我将引导模式封装在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

采用jsdom8/9作为解决问题的方法比我更难受通缉的应该很容易为添加一个伪实现getClientRects((只是为了克服特定的失败。我会试试的看看进展如何

添加getClientRects((的存根实现非常简单。我已经发布了5.0.1,并修复了此特定故障。

mdlavin