• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3var common = require('./common');
4var EventEmitter = require('../');
5var assert = require('assert');
6
7var myEE = new EventEmitter();
8var m = 0;
9// This one comes last.
10myEE.on('foo', common.mustCall(function () {
11  assert.strictEqual(m, 2);
12}));
13
14// This one comes second.
15myEE.prependListener('foo', common.mustCall(function () {
16  assert.strictEqual(m++, 1);
17}));
18
19// This one comes first.
20myEE.prependOnceListener('foo',
21                         common.mustCall(function () {
22                           assert.strictEqual(m++, 0);
23                         }));
24
25myEE.emit('foo');
26
27// Verify that the listener must be a function
28assert.throws(function () {
29  var ee = new EventEmitter();
30  ee.prependOnceListener('foo', null);
31}, 'TypeError: The "listener" argument must be of type Function. Received type object');
32