forked from Urigo/angular-meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-meteor-session-spec.js
64 lines (48 loc) · 1.56 KB
/
angular-meteor-session-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
describe('$meteorSession service', function () {
var $meteorSession,
$rootScope,
$scope;
beforeEach(angular.mock.module('angular-meteor'));
beforeEach(angular.mock.inject(function(_$meteorSession_, _$rootScope_) {
$meteorSession = _$meteorSession_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
}));
it('should update the scope variable when session variable changes', function () {
Session.set('myVar', 3);
$meteorSession('myVar').bind($scope, 'myVar');
Session.set('myVar', 4);
Tracker.flush(); // get the computations to run
expect($scope.myVar).toEqual(4);
});
it('should update the session variable when the scope variable changes', function() {
$scope.myVar = 3;
$meteorSession('myVar').bind($scope, 'myVar');
$scope.myVar = 4;
$rootScope.$apply();
expect(Session.get('myVar')).toEqual(4);
});
it('should update the scope variable nested property when session variable changes', function () {
Session.set('myVar', 3);
$scope.a ={
b:{
myVar: 3
}
};
$meteorSession('myVar').bind($scope, 'a.b.myVar');
Session.set('myVar', 4);
Tracker.flush(); // get the computations to run
expect($scope.a.b.myVar).toEqual(4);
});
it('should update the session variable when the scope variable nested property changes', function() {
$scope.a ={
b:{
myVar: 3
}
};
$meteorSession('myVar').bind($scope, 'a.b.myVar');
$scope.a.b.myVar = 4;
$rootScope.$apply();
expect(Session.get('myVar')).toEqual(4);
});
});