Skip to content

Commit

Permalink
a test for instances
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 19, 2010
1 parent 130a833 commit 1adf75a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Traverse (refObj) {
node[key] = clone(ref[key]);
});
// To make instanceof work:
if ('__proto__' in ref) node.__proto__ = ref.__proto__;
node.__proto__ = ref.__proto__;
// Probably there are other attributes worth copying
return node;
}
Expand Down
18 changes: 18 additions & 0 deletions test/instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse');
var EventEmitter = require('events').EventEmitter;

exports['check instanceof on node elems'] = function (assert) {

var counts = { emitter : 0 };

Traverse([ new EventEmitter, 3, 4, { ev : new EventEmitter }])
.forEach(function (node) {
if (node instanceof EventEmitter) counts.emitter ++;
})
;

assert.equal(counts.emitter, 2);
};

0 comments on commit 1adf75a

Please sign in to comment.