| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- describe('Misc Features', function () {
- var nextTick = require('vue/src/utils').nextTick
-
- describe('inline expression', function () {
- it('should evaluate the correct value', function (done) {
- var v = new Vue({
- template: '{{a + "123" + b}} and {{c}}'
- })
- v.a = 'A'
- v.b = 'B'
- v.c = 'C'
- nextTick(function () {
- assert.strictEqual(v.$el.textContent, 'A123B and C')
- done()
- })
- })
- })
- describe('expression inside attributes', function () {
- it('should interpolate the attribute', function (done) {
- var v = new Vue({
- attributes: {
- test: 'one {{msg}} three'
- },
- data: {
- msg: 'two'
- }
- })
- assert.strictEqual(v.$el.getAttribute('test'), 'one two three')
- v.msg = '2'
- nextTick(function () {
- assert.strictEqual(v.$el.getAttribute('test'), 'one 2 three')
- done()
- })
- })
- })
- describe('computed properties', function () {
- it('should be accessible like a normal attribtue', function () {
- var b = 2
- var v = new Vue({
- data: {
- a: 1,
- },
- computed: {
- test: {
- $get: function () {
- return this.a + b
- },
- $set: function (v) {
- b = v - this.a
- }
- },
- getOnly: function () {
- return this.a + 1
- }
- }
- })
- assert.strictEqual(v.test, 3)
- assert.strictEqual(v.getOnly, 2)
- v.a = 2
- assert.strictEqual(v.test, 4)
- assert.strictEqual(v.getOnly, 3)
- b = 3
- assert.strictEqual(v.test, 5)
- v.test = 10
- assert.strictEqual(b, 8)
- })
- })
- describe('setting an object to empty', function () {
- it('should emit undefined for paths in the old object', function (done) {
- var v = new Vue({
- data: {
- a: {
- b: { c: 1 }
- }
- }
- })
- var emitted = false
- v.$watch('a.b.c', function (v) {
- assert.strictEqual(v, undefined)
- emitted = true
- })
- v.a = {}
- nextTick(function () {
- assert.ok(emitted)
- done()
- })
- })
- })
- })
|