jquery/qunit — Issue #182: equal has a non-clear behaviour with JSON objects
Author: aledalgrande
Created: 2011-12-08 13:44:17+00:00
State: open

Hi,
I was testing my JS code with QUnit and I had a test failing like this:

```
Marker's location
Expected:
{
"accuracy": "8",
"lat": "33.389689",
"lng": "-111.853909",
"streetAddress": "1337 South Alma School Road",
"city": "Mesa",
"county": "AZ",
"country": "United States",
"org": "Best Buy",
"address": "1337 South Alma School Road, Mesa, AZ",
"postcode": undefined
}
Source:
at Object. (file://localhost/Users/ale/Desktop/projects/recycleopedia.com/jsmessupfix/test.js:114:2)
```

The content of the two objects was the same, but I guess it's comparing them to see if they're exactly the same. In fact, if I change just one value inside the expected JSON object I get:

```

Marker's location
Expected:
{
"accuracy": "0",
"lat": "33.389689",
"lng": "-111.853909",
"streetAddress": "1337 South Alma School Road",
"city": "Mesa",
"county": "AZ",
"country": "United States",
"org": "Best Buy",
"address": "1337 South Alma School Road, Mesa, AZ",
"postcode": undefined
}
Result:
{
"accuracy": "8",
"lat": "33.389689",
"lng": "-111.853909",
"streetAddress": "1337 South Alma School Road",
"city": "Mesa",
"county": "AZ",
"country": "United States",
"org": "Best Buy",
"address": "1337 South Alma School Road, Mesa, AZ",
"postcode": undefined
}
Diff:
{
"accuracy": "0",
"8",
"lat": "33.389689",
"lng": "-111.853909",
"streetAddress": "1337 South Alma School Road",
"city": "Mesa",
"county": "AZ",
"country": "United States",
"org": "Best Buy",
"address": "1337 South Alma School Road, Mesa, AZ",
"postcode": undefined
}
Source:
at Object. (file://localhost/Users/ale/Desktop/projects/recycleopedia.com/jsmessupfix/test.js:114:2)
```

I fixed applying JSON.stringify on both the output of my function and the expected JSON object.

I think that if the behaviour here cannot be changed to compare the objects field by field, at least there should be a clearer message to point out what is happening.

Thanks,
Alessandro