busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

array equality with prototypejs 1.6.1 #206

Closed sdepold closed 12 years ago

sdepold commented 12 years ago

When u have prototype 1.6.1 included in your project, the check for array equality isn't working. So smth like expect([1,2]).toEqual([1,2]) is not working.

you can see the complete test suite here: https://gist.github.com/3017220

cjohansen commented 12 years ago

I guess the general problem is augmented natives?

sdepold commented 12 years ago

i guess so. i've no clue how toEqual works internally, but if it compares all the properties of the arrays, the issue might be, that prototype is extending all arrays with special, unique properties.

cjohansen commented 12 years ago

Not quite sure how to handle this. The problem is that extending Array.prototype causes the native Object.keys to include things like each. Buster fails the assertion because keys includes each, but Object.prototype.hasOwnProperty.call(actual, key) fails for e.g. each. I tried recreating a small example, but failed to do so... :) Here's what I did:

    var Thing = function () {};
    var a = new Thing();
    var b = new Thing();
    a.id = 12;
    b.id = 12;
    Thing.prototype.method = function () {};

Problem is that, for this case, method is obviously not an enumerable property on a or b, so it doesn't trigger the same bug. I guess I have to extend Array.prototype in the test in order to reproduce?

cjohansen commented 12 years ago

Found out that the problem is that Prototype overwrites the native Object.keys with an inferior version that doesn't check for own properties (thus causing the assertion to fail due to Prototype's own added array methods...)

Fixed in https://github.com/busterjs/buster-assertions/commit/9b923ae67384f42ee9d274fd4f3a79182aeb1d7b

sdepold commented 12 years ago

Awesome!!!!!!1111

Am 09.07.2012 um 21:21 schrieb Christian Johansen reply@reply.github.com:

Found out that the problem is that Prototype overwrites the native Object.keys with an inferior version that doesn't check for own properties (thus causing the assertion to fail due to Prototype's own added array methods...)

Fixed in https://github.com/busterjs/buster-assertions/commit/9b923ae67384f42ee9d274fd4f3a79182aeb1d7b


Reply to this email directly or view it on GitHub: https://github.com/busterjs/buster/issues/206#issuecomment-6856727