Charlie Fish Charlie Fish - 1 month ago 17
Node.js Question

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

So first I have read this Stack Overflow question and it doesn't look like my same issue.

Basically I'm trying to use Mocha and Zombie.js to run some tests on my Node.js site.

I'm trying to check to see if I can create a user. In the end I would like to check to see if my bootstrap modal exists. Basically I have the bootstrap modal wrapped in an EJS

if
statement so there is defiantly a chance it might not exist. So that is why I'm trying to run tests on it.

But currently it's not even working with
browser.assert.success();
so I'm currently just trying to solve this before moving on to checking for elements.

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);
});


In this case I should be running the following code on the page the browser is currently on.

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


When running this unit test it gives me the following error.

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)


Looks to me like for some reason Zombie.js isn't loading jQuery on that page or there is an error. But in that previous Stack Overflow question and answer at the beginning of the question it looks like Zombie.js can load jQuery.

Are you not able to load jQuery with Zombie.js? How can I fix this? Seems like a very simple thing to test pages with jQuery. Any ideas?

Let me know if you need any additional information or anything. Thanks.

EDIT for some reason when downgrading to jQuery version
1.11.3
it seems to work and the error goes away. Any reason for this?

Answer

This bug is fixed : 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