【问题标题】:Zombie.js jQuery Load Error 'j.getClientRects is not a function'Zombie.js jQuery 加载错误'j.getClientRects 不是函数'
【发布时间】:2016-12-12 21:41:39
【问题描述】:

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

基本上我正在尝试使用 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 时它似乎可以工作并且错误消失了。这有什么原因吗?

【问题讨论】:

    标签: javascript jquery node.js mocha.js zombie.js


    【解决方案1】:

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

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

    添加 getClientRects() 的存根实现很简单。我已经发布了 5.0.1 并修复了这个特定的故障。

    mdlavin

    【讨论】:

      猜你喜欢
      • 2016-02-15
      • 2013-05-17
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 2014-08-02
      相关资源
      最近更新 更多