caolan / caolan/nodeunit

test.deepEqual gives AssertionError, without actual saying what property is not equal

Open
#165 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.9k
Forks
359
PR merge metrics
No merged PRs in 30d

Description

When test.deepEqual fails, we get a generic "AssertionError" message, without stating what property was mismatched. This requires you to scan the two objects to see what fails.

For example, I am trying a deepEqual test on two mongo schemas that seem to be exactly the same:


  var mongoose = require('mongoose'),
  ObjectId = mongoose.Schema.ObjectId;

  module.exports = {
    'deep equals works for mongooose schemas' : function(test){
      // SETUP/TEST
      var schemaA = new mongoose.Schema({keyA : String, keyB : ObjectId});
      var schemaB = new mongoose.Schema({keyA : String, keyB : ObjectId});
      // ASSERT
      test.deepEqual(schemaA, schemaB);
      test.done();
    }
  };

This gives me the following error when running the test:


✖ deep equals works for mongooose schemas

AssertionError:
{ paths:
   { keyA:
      { enumValues: [],
        regExp: null,
        path: 'keyA',
        instance: 'String',
        validators: [],
        setters: [],
        getters: [],
        options: { type: [Function: String] },
        _index: null },
     keyB:
      { path: 'keyB',
        instance: 'ObjectID',
        validators: [],
        setters: [],
        getters: [],
        options: { type: [Function: ObjectId] },
        _index: null },
     _id:
      { path: '_id',
        instance: 'ObjectID',
        validators: [],
        setters: [ [Function] ],
        getters: [],
        options: { type: [Function: ObjectId], auto: true },
        _index: null,
        defaultValue: [Function] } },
  virtuals: { id: { getters: [ [Function] ], setters: [], options: {} } },
  inherits: {},
  callQueue: [],
  _indexes: [],
  methods: {},
  statics: {},
  tree:
   { keyA: [Function],
     keyB: [Function],
     _id: { auto: true, type: [Function] },
     id: { getters: [ [Function] ], setters: [], options: {} } },
  options: { strict: false, 'use$SetOnSave': true, safe: true } }
deepEqual
{ paths:
   { keyA:
      { enumValues: [],
        regExp: null,
        path: 'keyA',
        instance: 'String',
        validators: [],
        setters: [],
        getters: [],
        options: { type: [Function: String] },
        _index: null },
     keyB:
      { path: 'keyB',
        instance: 'ObjectID',
        validators: [],
        setters: [],
        getters: [],
        options: { type: [Function: ObjectId] },
        _index: null },
     _id:
      { path: '_id',
        instance: 'ObjectID',
        validators: [],
        setters: [ [Function] ],
        getters: [],
        options: { type: [Function: ObjectId], auto: true },
        _index: null,
        defaultValue: [Function] } },
  virtuals: { id: { getters: [ [Function] ], setters: [], options: {} } },
  inherits: {},
  callQueue: [],
  _indexes: [],
  methods: {},
  statics: {},
  tree:
   { keyA: [Function],
     keyB: [Function],
     _id: { auto: true, type: [Function] },
     id: { getters: [ [Function] ], setters: [], options: {} } },
  options: { strict: false, 'use$SetOnSave': true, safe: true } }
    at Object.deepEqual (d:\Source\MySource\mongoose-strongly\tests\node_modules\nodeunit\lib\types.js:83:39)

A) I have to scan all the properties and try to see what's different, and B) the objects seem identical, what is actually different?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at nodeunit/lib/types.js:83, where the reported deepEqual failure is raised, and reproduce the mongoose schema example from the issue. Trace how the compared values are rendered and identify what information is available for a property-level mismatch. Done means the AssertionError identifies the differing property or value instead of only printing the two full objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.