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 pathViewModel.test.ts
More file actions
64 lines (48 loc) · 1.73 KB
/
ViewModel.test.ts
File metadata and controls
64 lines (48 loc) · 1.73 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
/// <reference path="../typings/tsd.d.ts" />
import chai = require("chai");
import ViewModel = require("../ViewModel");
import View = require("../View");
var assert = chai.assert;
describe('ViewModel', function () {
describe('constructor()', function () {
it('should set data from the constructor', function () {
var vm = new ViewModel({ a: 42 });
assert.strictEqual(vm['a'], 42);
});
});
describe('findValue()', function() {
it ('should find a value from root', function() {
var rootView = new View();
var childView = <View>rootView.addChild(new View());
var grandChildView = childView.addChild(new View());
rootView.setData({
foo: { bar: 'baz' }
});
childView.setData({
foo: { baz: 'boz' }
});
rootView.activate();
assert.strictEqual(grandChildView.viewModel.findValue('foo.bar'), 'baz');
});
});
describe('setData()', function() {
it('should set data', function() {
var vm = new ViewModel();
assert.strictEqual(vm['foo'], undefined);
vm.setData({foo: 'hello world'});
assert.strictEqual(vm['foo'], 'hello world');
});
it('should not set data from the prototype', function() {
var vm = new ViewModel();
var ParentClass = function() {
this.foo = 42;
};
var SubClass = function() {
this.bar = 'hello';
};
SubClass.prototype = new ParentClass();
vm.setData(new SubClass());
assert.strictEqual(vm['foo'], undefined);
});
});
});