1

I want to test a serialize function of a nodejs module I've written.

In my tests I have the following strange behavior:

assert.equal(JSON.stringify(obj1), JSON.stringify(obj2)); // => TEST OK
assert.deepEqual(obj1, obj2); // => TEST FAILS

I have no clue what is going wrong here. The objects seem to look identical in my opinion.

obj1:

{
    "config": {
        "index_amount": 12,
        "ignore_case": true,
        "debug": false
    },
    "indexes": [{
        "p": [0, 1],
        "e": [0],
        "t": [0],
        "r": [0, 2],
        "a": [1, 2],
        "u": [1],
        "l": [1],
        "m": [2],
        "i": [2]
    }, {
        "pe": [0],
        "et": [0],
        "te": [0],
        "er": [0],
        "pa": [1],
        "au": [1],
        "ul": [1],
        "ma": [2],
        "ar": [2],
        "ri": [2],
        "ia": [2]
    }, {
        "pet": [0],
        "ete": [0],
        "ter": [0],
        "pau": [1],
        "aul": [1],
        "mar": [2],
        "ari": [2],
        "ria": [2]
    }, {
        "pete": [0],
        "eter": [0],
        "paul": [1],
        "mari": [2],
        "aria": [2]
    }, {
        "peter": [0],
        "maria": [2]
    }, {}, {}, {}, {}, {}, {}, {}],
    "data": ["Peter", "Paul", "Maria"],
    "data_ptr": 3,
    "free_slots": [],
    "single_data_counter": 3
}

obj2:

{
    "config": {
        "index_amount": 12,
        "ignore_case": true,
        "debug": false
    },
    "indexes": [{
        "p": [0, 1],
        "e": [0],
        "t": [0],
        "r": [0, 2],
        "a": [1, 2],
        "u": [1],
        "l": [1],
        "m": [2],
        "i": [2]
    }, {
        "pe": [0],
        "et": [0],
        "te": [0],
        "er": [0],
        "pa": [1],
        "au": [1],
        "ul": [1],
        "ma": [2],
        "ar": [2],
        "ri": [2],
        "ia": [2]
    }, {
        "pet": [0],
        "ete": [0],
        "ter": [0],
        "pau": [1],
        "aul": [1],
        "mar": [2],
        "ari": [2],
        "ria": [2]
    }, {
        "pete": [0],
        "eter": [0],
        "paul": [1],
        "mari": [2],
        "aria": [2]
    }, {
        "peter": [0],
        "maria": [2]
    }, {}, {}, {}, {}, {}, {}, {}],
    "data": ["Peter", "Paul", "Maria"],
    "data_ptr": 3,
    "free_slots": [],
    "single_data_counter": 3
}
jophab
  • 5,356
  • 14
  • 41
  • 60
Frank Roth
  • 6,191
  • 3
  • 25
  • 33
  • 3
    What are `obj1` and `obj2`? – thefourtheye Apr 29 '15 at 06:42
  • possible duplicate of [The difference between assert.equal and assert.deepEqual in Javascript testing with Mocha?](http://stackoverflow.com/questions/13225274/the-difference-between-assert-equal-and-assert-deepequal-in-javascript-testing-w) – Mekap Apr 29 '15 at 06:44
  • @Mekap it's not a duplicate - just impossible to debug. – Benjamin Gruenbaum Apr 29 '15 at 06:45
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – thefourtheye Apr 29 '15 at 06:48
  • Added the code, sorry for that. It is a little bit complex – Frank Roth Apr 29 '15 at 07:31
  • @FrankRoth We just want to see `obj1` and `obj2` – thefourtheye Apr 29 '15 at 10:14
  • @thefourtheye postet them, but they are identical like I said – Frank Roth Apr 29 '15 at 10:27
  • @FrankRoth I don't get any assertion error, when I do `assert.deepEqual(obj1, obj2, "Not matching");` – thefourtheye Apr 29 '15 at 10:33
  • Therefore I posted my Prototype object. Maybe there are some differents in functions. But it was deleted... – Frank Roth Apr 29 '15 at 10:39
  • i can see these are the json representation are you sure the original objects do not differ on any undefined properties? not 100% sure but if obj1 has a property set as undefined it wouldn't be represented in the json string but it would be taken into account for a deep equal – Dayan Moreno Leon Dec 31 '16 at 08:13

0 Answers0