This repository has been archived by the owner. It is now read-only.

array equality with prototypejs 1.6.1 #206

Closed
sdepold opened this Issue Jun 29, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@sdepold

sdepold commented Jun 29, 2012

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

This comment has been minimized.

Member

cjohansen commented Jul 5, 2012

I guess the general problem is augmented natives?

@sdepold

This comment has been minimized.

sdepold commented Jul 5, 2012

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

This comment has been minimized.

Member

cjohansen commented Jul 5, 2012

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?

@ghost ghost assigned cjohansen Jul 6, 2012

@cjohansen

This comment has been minimized.

Member

cjohansen commented Jul 9, 2012

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

@cjohansen cjohansen closed this Jul 9, 2012

@sdepold

This comment has been minimized.

sdepold commented Jul 9, 2012

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:
#206 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.