nodeunit icon indicating copy to clipboard operation
nodeunit copied to clipboard

test.deepEqual may print incorrect property values for subsequently modified properties SERIOUS ISSUE

Open haraldrudell opened this issue 12 years ago • 1 comments

test.deepEqual does not examine failing objects immediately, so incorrect values are printed

Reproduction printout

$ nodeunit ../nodejs3/snippets/modules/nodeunit/nodeunit-changedobject.js 

nodeunit-changedobject.js
Expected printout: AssertionError: { property: 'object1' } deepEqual { property: 'object2' }
✖ f

AssertionError: { property: 'overwite' } deepEqual { property: 'object2' }
    at Object.assertWrapper [as deepEqual] (/usr/local/lib/node_modules/nodeunit/lib/types.js:83:39)
    at Object.module.exports.f (/home/foxyboy/Desktop/c505/node/nodejs3/snippets/modules/nodeunit/nodeunit-changedobject.js:13:7)
    at Object.wrapTest (/usr/local/lib/node_modules/nodeunit/lib/core.js:235:16)
    at wrapTest (/usr/local/lib/node_modules/nodeunit/lib/core.js:235:16)
    at Object.exports.runTest (/usr/local/lib/node_modules/nodeunit/lib/core.js:69:9)
    at exports.runSuite (/usr/local/lib/node_modules/nodeunit/lib/core.js:117:25)
    at _concat (/usr/local/lib/node_modules/nodeunit/deps/async.js:508:13)
    at async.forEachSeries.iterate (/usr/local/lib/node_modules/nodeunit/deps/async.js:118:13)
    at async.forEachSeries (/usr/local/lib/node_modules/nodeunit/deps/async.js:134:9)
    at _concat (/usr/local/lib/node_modules/nodeunit/deps/async.js:507:9)

Reproduction code

// nodeunit-changedobject.js


module.exports.f = function (test) {

    var object1 = {
        property: 'object1'
    }
    var object2 = {
        property: 'object2'
    }

    test.deepEqual(object1, object2)
    object1.property = 'overwite'

    console.log('Expected printout: AssertionError: { property: \'object1\' } deepEqual { property: \'object2\' }')
    test.done()
}

haraldrudell avatar Jul 30 '12 00:07 haraldrudell

mochawrapper

I just wrote a node module that automates coverage reporting. It is based on mocha, jscoverage and node's assert. You do not have to modify require or use make or enviornment variables.

It is hosted on github: https://github.com/haraldrudell/mochawrapper

haraldrudell avatar Aug 22 '12 08:08 haraldrudell