misc.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. describe('Misc Features', function () {
  2. var nextTick = require('vue/src/utils').nextTick
  3. describe('inline expression', function () {
  4. it('should evaluate the correct value', function (done) {
  5. var v = new Vue({
  6. template: '{{a + "123" + b}} and {{c}}'
  7. })
  8. v.a = 'A'
  9. v.b = 'B'
  10. v.c = 'C'
  11. nextTick(function () {
  12. assert.strictEqual(v.$el.textContent, 'A123B and C')
  13. done()
  14. })
  15. })
  16. })
  17. describe('expression inside attributes', function () {
  18. it('should interpolate the attribute', function (done) {
  19. var v = new Vue({
  20. attributes: {
  21. test: 'one {{msg}} three'
  22. },
  23. data: {
  24. msg: 'two'
  25. }
  26. })
  27. assert.strictEqual(v.$el.getAttribute('test'), 'one two three')
  28. v.msg = '2'
  29. nextTick(function () {
  30. assert.strictEqual(v.$el.getAttribute('test'), 'one 2 three')
  31. done()
  32. })
  33. })
  34. })
  35. describe('computed properties', function () {
  36. it('should be accessible like a normal attribtue', function () {
  37. var b = 2
  38. var v = new Vue({
  39. data: {
  40. a: 1,
  41. },
  42. computed: {
  43. test: {
  44. $get: function () {
  45. return this.a + b
  46. },
  47. $set: function (v) {
  48. b = v - this.a
  49. }
  50. },
  51. getOnly: function () {
  52. return this.a + 1
  53. }
  54. }
  55. })
  56. assert.strictEqual(v.test, 3)
  57. assert.strictEqual(v.getOnly, 2)
  58. v.a = 2
  59. assert.strictEqual(v.test, 4)
  60. assert.strictEqual(v.getOnly, 3)
  61. b = 3
  62. assert.strictEqual(v.test, 5)
  63. v.test = 10
  64. assert.strictEqual(b, 8)
  65. })
  66. })
  67. describe('setting an object to empty', function () {
  68. it('should emit undefined for paths in the old object', function (done) {
  69. var v = new Vue({
  70. data: {
  71. a: {
  72. b: { c: 1 }
  73. }
  74. }
  75. })
  76. var emitted = false
  77. v.$watch('a.b.c', function (v) {
  78. assert.strictEqual(v, undefined)
  79. emitted = true
  80. })
  81. v.a = {}
  82. nextTick(function () {
  83. assert.ok(emitted)
  84. done()
  85. })
  86. })
  87. })
  88. })