misc.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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('triple mustache', function () {
  36. it('should set unescaped HTML', function () {
  37. var v = new Vue({
  38. template: '{{{html}}}',
  39. data: {
  40. html: '<span>a</span><a>hi</a>'
  41. }
  42. })
  43. assert.strictEqual(v.$el.innerHTML, '<span>a</span><a>hi</a><!--v-html-->')
  44. })
  45. })
  46. describe('computed properties', function () {
  47. it('should be accessible like a normal attribtue', function () {
  48. var b = 2
  49. var v = new Vue({
  50. data: {
  51. a: 1,
  52. },
  53. computed: {
  54. test: {
  55. $get: function () {
  56. return this.a + b
  57. },
  58. $set: function (v) {
  59. b = v - this.a
  60. }
  61. },
  62. getOnly: function () {
  63. return this.a + 1
  64. }
  65. }
  66. })
  67. assert.strictEqual(v.test, 3)
  68. assert.strictEqual(v.getOnly, 2)
  69. v.a = 2
  70. assert.strictEqual(v.test, 4)
  71. assert.strictEqual(v.getOnly, 3)
  72. b = 3
  73. assert.strictEqual(v.test, 5)
  74. v.test = 10
  75. assert.strictEqual(b, 8)
  76. })
  77. })
  78. describe('setting an object to empty', function () {
  79. it('should emit undefined for paths in the old object', function (done) {
  80. var v = new Vue({
  81. data: {
  82. a: {
  83. b: { c: 1 }
  84. }
  85. }
  86. })
  87. var emitted = false
  88. v.$watch('a.b.c', function (v) {
  89. assert.strictEqual(v, undefined)
  90. emitted = true
  91. })
  92. v.a = {}
  93. nextTick(function () {
  94. assert.ok(emitted)
  95. done()
  96. })
  97. })
  98. })
  99. })