Skip to content

Commit

Permalink
test: test add and remove for lib/domain
Browse files Browse the repository at this point in the history
Testing some of the more specific cases of using domain.add and
domain.remove. For example, calling domain.add twice with same event
emmiter and actually removing an event emitter from the domain.
  • Loading branch information
dodev committed Nov 7, 2018
1 parent 5850220 commit 339facb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/parallel/test-domain-add-remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

require('../common');
const assert = require('assert');
const domain = require('domain');
const EventEmitter = require('events');

const d = new domain.Domain();
const e = new EventEmitter();
const e2 = new EventEmitter();

d.add(e);
assert.strictEqual(e.domain, d);

// Adding the same event to a domain should not change the member count
let previousMemberCount = d.members.length;
d.add(e);
assert.strictEqual(previousMemberCount, d.members.length);

d.add(e2);
assert.strictEqual(e2.domain, d);

previousMemberCount = d.members.length;
d.remove(e2);
assert.notStrictEqual(e2.domain, d);
assert.strictEqual(previousMemberCount - 1, d.members.length);

0 comments on commit 339facb

Please sign in to comment.