mirror of https://github.com/vuejs/vue.git
test for computed properties and _.bind
This commit is contained in:
parent
f2798b6924
commit
18e50c4570
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
exports.bind = function (fn, ctx) {
|
||||
return function () {
|
||||
fn.apply(ctx, arguments)
|
||||
return fn.apply(ctx, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -232,4 +232,62 @@ describe('Scope', function () {
|
|||
|
||||
})
|
||||
|
||||
describe('computed', function () {
|
||||
|
||||
var vm = new Vue({
|
||||
data: {
|
||||
a: 'a',
|
||||
b: 'b'
|
||||
},
|
||||
computed: {
|
||||
c: function () {
|
||||
expect(this).toBe(vm)
|
||||
return this.a + this.b
|
||||
},
|
||||
d: {
|
||||
get: function () {
|
||||
expect(this).toBe(vm)
|
||||
return this.a + this.b
|
||||
},
|
||||
set: function (newVal) {
|
||||
expect(this).toBe(vm)
|
||||
var vals = newVal.split(' ')
|
||||
this.a = vals[0]
|
||||
this.b = vals[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('get', function () {
|
||||
expect(vm.c).toBe('ab')
|
||||
expect(vm.d).toBe('ab')
|
||||
})
|
||||
|
||||
it('set', function () {
|
||||
vm.c = 123 // should do nothing
|
||||
vm.d = 'c d'
|
||||
expect(vm.a).toBe('c')
|
||||
expect(vm.b).toBe('d')
|
||||
expect(vm.c).toBe('cd')
|
||||
expect(vm.d).toBe('cd')
|
||||
})
|
||||
|
||||
it('inherit', function () {
|
||||
var child = new Vue({ parent: vm })
|
||||
expect(child.$scope.c).toBe('cd')
|
||||
|
||||
child.$scope.d = 'e f'
|
||||
expect(vm.a).toBe('e')
|
||||
expect(vm.b).toBe('f')
|
||||
expect(vm.c).toBe('ef')
|
||||
expect(vm.d).toBe('ef')
|
||||
expect(child.$scope.a).toBe('e')
|
||||
expect(child.$scope.b).toBe('f')
|
||||
expect(child.$scope.c).toBe('ef')
|
||||
expect(child.$scope.d).toBe('ef')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -5,6 +5,16 @@ config.silent = true
|
|||
describe('Util', function () {
|
||||
|
||||
describe('Language Enhancement', function () {
|
||||
|
||||
it('bind', function () {
|
||||
var original = function (a) {
|
||||
return this.a + a
|
||||
}
|
||||
var ctx = { a: 'ctx a ' }
|
||||
var bound = _.bind(original, ctx)
|
||||
var res = bound('arg a')
|
||||
expect(res).toBe('ctx a arg a')
|
||||
})
|
||||
|
||||
it('toArray', function () {
|
||||
// should make a copy of original array
|
||||
|
|
|
|||
Loading…
Reference in New Issue