render-proxy.spec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Vue from 'vue'
  2. if (typeof Proxy !== 'undefined') {
  3. describe('render proxy', () => {
  4. it('should warn missing property in render fns with `with`', () => {
  5. new Vue({
  6. template: `<div>{{ a }}</div>`
  7. }).$mount()
  8. expect(`Property or method "a" is not defined`).toHaveBeenWarned()
  9. })
  10. it('should warn missing property in render fns without `with`', () => {
  11. const render = function (h) {
  12. return h('div', [this.a])
  13. }
  14. render._withStripped = true
  15. new Vue({
  16. render
  17. }).$mount()
  18. expect(`Property or method "a" is not defined`).toHaveBeenWarned()
  19. })
  20. it('should not warn for hand-written render functions', () => {
  21. new Vue({
  22. render (h) {
  23. return h('div', [this.a])
  24. }
  25. }).$mount()
  26. expect(`Property or method "a" is not defined`).not.toHaveBeenWarned()
  27. })
  28. it('support symbols using the `in` operator in hand-written render functions', () => {
  29. const sym = Symbol()
  30. const vm = new Vue({
  31. created () {
  32. this[sym] = 'foo'
  33. },
  34. render (h) {
  35. if (sym in this) {
  36. return h('div', [this[sym]])
  37. }
  38. }
  39. }).$mount()
  40. expect(vm.$el.textContent).toBe('foo')
  41. })
  42. it('should warn properties starting with $ when found', () => {
  43. new Vue({
  44. data: { $a: 'foo' },
  45. template: `<div>{{ $a }}</div>`
  46. }).$mount()
  47. expect(`Property "$a" must be accessed with "$data.$a"`).toHaveBeenWarned()
  48. })
  49. it('should warn properties starting with _ when found', () => {
  50. new Vue({
  51. data: { _foo: 'foo' },
  52. template: `<div>{{ _foo }}</div>`
  53. }).$mount()
  54. expect(`Property "_foo" must be accessed with "$data._foo"`).toHaveBeenWarned()
  55. })
  56. it('should warn properties starting with $ when not found', () => {
  57. new Vue({
  58. template: `<div>{{ $a }}</div>`
  59. }).$mount()
  60. expect(`Property or method "$a" is not defined`).toHaveBeenWarned()
  61. expect(`Property "$a" must be accessed with "$data.$a"`).not.toHaveBeenWarned()
  62. })
  63. it('should warn properties starting with $ when not found (with stripped)', () => {
  64. const render = function (h) {
  65. return h('p', this.$a)
  66. }
  67. render._withStripped = true
  68. new Vue({
  69. data: { $a: 'foo' },
  70. render
  71. }).$mount()
  72. expect(`Property "$a" must be accessed with "$data.$a"`).toHaveBeenWarned()
  73. })
  74. it('should not warn properties starting with $ when using $data to access', () => {
  75. new Vue({
  76. data: { $a: 'foo' },
  77. template: `<div>{{ $data.$a }}</div>`
  78. }).$mount()
  79. expect(`Property or method "$a" is not defined`).not.toHaveBeenWarned()
  80. })
  81. })
  82. }