forked from SpringRoll/SpringRoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperty.spec.js
64 lines (50 loc) · 1.83 KB
/
Property.spec.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
import { Property } from './Property';
import Sinon from 'sinon';
describe('Property', () => {
describe('subscribe', () => {
it('should notify the subscriber whenever the property changes', () => {
const callback = Sinon.fake();
const property = new Property(7);
property.subscribe(callback);
property.value = 8;
expect(callback.callCount).to.equal(1);
expect(property.value).to.equal(8);
});
it('should not invoke listeners if the provided value is the same as the current value', () => {
const callback = Sinon.fake();
const property = new Property(8);
property.subscribe(callback);
property.value = 8;
expect(callback.callCount).to.equal(0);
});
it('should invoke listeners if flagged to always notify and provided value is the same as the current value.', () => {
const callback = Sinon.fake();
const property = new Property(8, true);
property.subscribe(callback);
property.value = 8;
expect(callback.callCount).to.equal(1);
});
});
describe('unsubscribe', () => {
it('should notify listeners that are unsubscribed', () => {
const callback = Sinon.fake();
const property = new Property(1);
property.subscribe(callback);
property.unsubscribe(callback);
property.value = 0;
expect(callback.callCount).to.equal(0);
expect(property.value).to.equal(0);
});
});
describe('hasListeners', () => {
it('should be true if the property has a listener', () => {
const property = new Property(0);
property.subscribe(() => {});
expect(property.hasListeners).to.equal(true);
});
it('should be false if the property does not have a listener', () => {
const property = new Property(0);
expect(property.hasListeners).to.equal(false);
});
});
});