This repository was archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathObservable.test.ts
More file actions
67 lines (51 loc) · 2.02 KB
/
Observable.test.ts
File metadata and controls
67 lines (51 loc) · 2.02 KB
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
/// <reference path="../typings/tsd.d.ts" />
import chai = require("chai");
import Observable = require("../Observable");
import EventGroup = require("../EventGroup");
var assert = chai.assert;
describe('Observable', function() {
describe('constructor()', function() {
it('should take a value from the constructor', function() {
var obs = new Observable('foo');
assert.strictEqual(obs._val, 'foo');
});
it('should be undefined with no value', function() {
var obs = new Observable();
assert.isUndefined(obs._val);
});
it('should instantiate an instance of EventGroup', function() {
var obs = new Observable();
assert.instanceOf(obs._events, EventGroup);
});
});
describe('getValue()', function() {
it('should get a value passed in through the constructor', function() {
var obs = new Observable('foo');
assert.strictEqual(obs.getValue(), 'foo');
});
});
describe('setValue()', function() {
it('should set a value', function() {
var obs = new Observable();
obs.setValue('foo');
assert.strictEqual(obs.getValue(), 'foo');
obs.setValue('bar');
assert.strictEqual(obs.getValue(), 'bar');
});
});
describe('change event', function() {
it('should fire when the value changes', function() {
var obs = new Observable();
var events = new EventGroup({});
var wasChanged = false;
events.on(obs, 'change', function() { wasChanged = true; });
obs.setValue('foo');
assert.isTrue(wasChanged, 'did not change when assigning value foo');
wasChanged = false;
obs.setValue('foo');
assert.isFalse(wasChanged, 'changed when the value didn\'t change');
obs.setValue('bar');
assert.isTrue(wasChanged, 'did not change when assigning value bar');
});
});
});