misc.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. test: {
  42. $get: function () {
  43. return this.a + b
  44. },
  45. $set: function (v) {
  46. b = v - this.a
  47. }
  48. }
  49. }
  50. })
  51. assert.strictEqual(v.test, 3)
  52. v.a = 2
  53. assert.strictEqual(v.test, 4)
  54. b = 3
  55. assert.strictEqual(v.test, 5)
  56. v.test = 10
  57. assert.strictEqual(b, 8)
  58. })
  59. })
  60. describe('setting an object to empty', function () {
  61. it('should emit undefined for paths in the old object', function (done) {
  62. var v = new Vue({
  63. data: {
  64. a: {
  65. b: { c: 1 }
  66. }
  67. }
  68. })
  69. var emitted = false
  70. v.$watch('a.b.c', function (v) {
  71. assert.strictEqual(v, undefined)
  72. emitted = true
  73. })
  74. v.a = {}
  75. nextTick(function () {
  76. assert.ok(emitted)
  77. done()
  78. })
  79. })
  80. })
  81. })