Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

t.equivalent may fail when object has a property with `null` value. #89

Closed
chakrit opened this Issue · 3 comments

2 participants

@chakrit

Test code:

var tap = require('tap');

tap.test(function(t) {
  var a = { hello: 'world', another: { nested: 'object' } }
    , b = { hello: 'world', another: null };

  t.equivalent(a, b, 'should just fails.');
  t.end();
});

Running node test.js results in

TAP version 13
# (anonymous)
not ok 1 TypeError: Cannot convert null to object
  ---
    type:    TypeError
    message: Cannot convert null to object
    code:    null_to_object
    errno:   ~
    file:    /private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js
    line:    13
    column:  36
    stack:   
      - hasOwnProperty (native)
      - Traverse.get (/private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:13:36)
      - Function.traverse.(anonymous function) [as get] (/private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:308:23)
      - Object.<anonymous> (/private/tmp/node_modules/tap/node_modules/difflet/index.js:212:40)
      - /private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:206:50
      - Array.forEach (native)
      - forEach (/private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:298:31)
      - walker (/private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:203:13)
      - /private/tmp/node_modules/tap/node_modules/difflet/node_modules/traverse/index.js:208:29
      - Array.forEach (native)
    thrown:  true
  ...

1..1
# tests 1
# fail  1

However if a, b is swapped during the test, it works fine (and report the failure and diff as expected):

TAP version 13
# (anonymous)
not ok 1 should just fails.
  ---
    file:   /private/tmp/test.js
    line:   8
    column: 5
    stack:  
      - getCaller (/private/tmp/node_modules/tap/lib/tap-assert.js:418:17)
      - assert (/private/tmp/node_modules/tap/lib/tap-assert.js:21:16)
      - Function.equivalent (/private/tmp/node_modules/tap/lib/tap-assert.js:182:12)
      - Test._testAssert [as equivalent] (/private/tmp/node_modules/tap/lib/tap-test.js:87:16)
      - Test.<anonymous> (/private/tmp/test.js:8:5)
      - Test.EventEmitter.emit (events.js:117:20)
      - Test.emit (/private/tmp/node_modules/tap/lib/tap-test.js:104:8)
      - GlobalHarness.Harness.process (/private/tmp/node_modules/tap/lib/tap-harness.js:87:13)
      - process._tickCallback (node.js:415:13)
      - Function.Module.runMain (module.js:499:11)
    found:  
      hello:   world
      another: ~
    wanted: 
      hello:   world
      another: 
        nested: object
    diff:   |
      {
        "hello" : "world",
        "another" : �[34m�[1mnull�[0m
      }
  ...

1..1
# tests 1
# fail  1

Although I can't reproduce this, in some tests that I am writing this also crash the tap runner (leading me to report this issue). When it does, only the node stacktrace is printed to stdout and the no report is printed in the output at all.

@chakrit

Seems this is a difflet issue. Filed: substack/difflet#17

Will close this once I've confirmed the fix.

@kytwb

This has been fixed by substack/js-traverse#28

@chakrit

Confirm fixed.

The colored diff only appears when the arguments are in the a, b order, thoguh. But that's not a big deal.

@chakrit chakrit closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.