-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
84 lines (61 loc) · 1.6 KB
/
test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import tap from 'tap';
import Vue from 'vue';
import VueNonreactive from './vue-nonreactive';
Vue.use(VueNonreactive);
function derived() {
return this.obj.prop + 1;
}
const reactive = new Vue({
data() {
return {obj: {
sub: {},
prop: 0,
}};
},
computed: {
derived,
},
});
const nonReactive = new Vue({
data() {
const data = {obj: {
sub: {},
prop: 0,
}};
Vue.nonreactive(data.obj);
return data;
},
computed: {
derived,
},
});
tap.test('reactive data is reactive', t => {
t.plan(6);
const obj = reactive.$data.obj;
// obj should retain attributes
t.ok(obj.hasOwnProperty('sub'));
t.ok(obj.hasOwnProperty('prop'));
// all objects should be observed
t.type(obj.__ob__, 'Observer');
t.type(obj.sub.__ob__, 'Observer');
// derived should update on prop update
t.equal(reactive.derived, 1);
reactive.obj.prop += 1;
t.equal(reactive.derived, 2);
});
tap.test('non-reactive data is not reactive', t => {
t.plan(6);
const obj = nonReactive.$data.obj;
// obj should retain attributes
t.ok(obj.hasOwnProperty('sub'));
t.ok(obj.hasOwnProperty('prop'));
// primary obj should remain observed
// sub object should not be observed
t.type(obj.__ob__, 'Observer');
t.type(obj.sub.__ob__, 'undefined');
// derived should not update on prop update
// derived should update on prop update
t.equal(nonReactive.derived, 1);
nonReactive.obj.prop += 1;
t.equal(nonReactive.derived, 1);
});