-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreactive-var.tests.js
38 lines (26 loc) · 1.11 KB
/
reactive-var.tests.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
import { Tinytest } from "meteor/tinytest";
import { ReactiveVar } from 'meteor/reactive-var';
import './reactive-var';
Tinytest.add('ReactiveVar store contract', function (test) {
const rvar = new ReactiveVar("initial");
let setterCalled = 0;
let setterCalledWith;
function setter(value) {
setterCalled += 1;
setterCalledWith = value;
}
const unsub = rvar.subscribe(setter);
test.equal(setterCalled, 1, 'Subscribe should have called setter once');
test.equal(setterCalledWith, "initial", 'Subscribe should have set initial value');
rvar.set("initial");
test.equal(setterCalled, 1, 'Setter should not be called if value is not changed');
rvar.get();
test.equal(setterCalled, 1, 'Setter should not be called on ReactiveVar.get()');
rvar.set("new");
test.equal(setterCalled, 2, 'Setter should be called if value is changed');
test.equal(setterCalledWith, "new", 'Setter should be called with new value');
unsub();
test.equal(setterCalled, 2, 'Unsubscribe should not call setter');
rvar.set("newer");
test.equal(setterCalled, 2, 'Setter may not be called after unsubscribe');
});