-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
90 lines (69 loc) · 2.38 KB
/
test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
describe('modification', function () {
'use strict';
var EventEmitter = require('events').EventEmitter
, modification = require('./')
, assume = require('assume')
, util = require('util')
, Fixture;
beforeEach(function () {
function Fix() {
EventEmitter.call(this);
this.foo = 'bar';
}
util.inherits(Fix, EventEmitter);
Fixture = Fix;
});
it('is exported as a function', function () {
assume(modification).is.a('function');
});
it('returns a function', function () {
assume(modification()).is.a('function');
});
it('it does not introduce new properties', function () {
Fixture.prototype.change = modification();
var fixture = new Fixture();
assume(fixture.bar).is.undefined();
fixture.change({ bar: 'hi', foo: 'mom' });
assume(fixture.bar).is.undefined();
});
it('changes the property if values are not equal', function () {
Fixture.prototype.change = modification();
var fixture = new Fixture();
assume(fixture.foo).equals('bar');
fixture.change({ foo: 'hi' });
assume(fixture.foo).equals('hi');
});
it('emits an event on the instance when things change', function (next) {
Fixture.prototype.change = modification(' changed');
var fixture = new Fixture();
fixture.once('foo changed', function (currently, previously) {
assume(fixture.foo).equals('hi');
assume(fixture.foo).equals(currently);
assume(previously).equals('bar');
next();
});
assume(fixture.foo).equals('bar');
fixture.change({ foo: 'hi' });
});
it('returns this', function () {
Fixture.prototype.change = modification(' changed');
var fixture = new Fixture();
assume(fixture.change()).equals(fixture);
assume(fixture.change({ foo: 'bar' })).equals(fixture);
assume(fixture.change({ bar: 'bar' })).equals(fixture);
assume(fixture.change({ bar: 'bar', foo: 'mom' })).equals(fixture);
assume(fixture.foo).equals('mom');
});
it('can be triggered without suffix', function (next) {
Fixture.prototype.change = modification();
var fixture = new Fixture();
fixture.once('foo', function (currently, previously) {
assume(fixture.foo).equals('hi');
assume(fixture.foo).equals(currently);
assume(previously).equals('bar');
next();
});
assume(fixture.foo).equals('bar');
fixture.change({ foo: 'hi' });
});
});