-
Notifications
You must be signed in to change notification settings - Fork 1
/
shouldNotEmit.js
43 lines (31 loc) · 1.13 KB
/
shouldNotEmit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* shouldNotEmit.js
*
* (C) 2012 Crosstalk Systems Inc.
*/
var assert = require( 'assert' ),
matchesHistoricalEvent = require( './matchesHistoricalEvent' );
//
// ### function shouldNotEmitConstructor ( wrapper )
// #### @wrapper {object} wrapper to attach this assertion to
// Constructs a shouldNotEmit assertion and attaches it to specified wrapper.
//
var shouldNotEmitConstructor = function shouldNotEmitConstructor ( wrapper ) {
var history = wrapper.history;
var shouldNotEmit = function shouldNotEmit ( message ) {
var eventToMatch = { message : message };
// 1. check history to see if this already happened
var matches = matchesHistoricalEvent( history._out, eventToMatch );
if ( matches ) {
assert.fail( null, matches, null, "==" );
}
// 2. hasn't happened yet
// attach an event listener that will cause failure if triggered
wrapper.on( message, function () {
assert.fail( null, message, null, "==" );
}); // wrapper.on( message )
return wrapper;
}; // shouldNotEmit
return shouldNotEmit;
}; // shouldNotEmitConstructor
module.exports = shouldNotEmitConstructor;