extends.spec.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import Vue from 'vue'
  2. import { nativeWatch } from 'core/util/env'
  3. describe('Options extends', () => {
  4. it('should work on objects', () => {
  5. const A = {
  6. data () {
  7. return { a: 1 }
  8. }
  9. }
  10. const B = {
  11. extends: A,
  12. data () {
  13. return { b: 2 }
  14. }
  15. }
  16. const vm = new Vue({
  17. extends: B,
  18. data: {
  19. c: 3
  20. }
  21. })
  22. expect(vm.a).toBe(1)
  23. expect(vm.b).toBe(2)
  24. expect(vm.c).toBe(3)
  25. })
  26. it('should work on extended constructors', () => {
  27. const A = Vue.extend({
  28. data () {
  29. return { a: 1 }
  30. }
  31. })
  32. const B = Vue.extend({
  33. extends: A,
  34. data () {
  35. return { b: 2 }
  36. }
  37. })
  38. const vm = new Vue({
  39. extends: B,
  40. data: {
  41. c: 3
  42. }
  43. })
  44. expect(vm.a).toBe(1)
  45. expect(vm.b).toBe(2)
  46. expect(vm.c).toBe(3)
  47. })
  48. if (nativeWatch) {
  49. it('should work with global mixins + Object.prototype.watch', done => {
  50. Vue.mixin({})
  51. const spy = jasmine.createSpy('watch')
  52. const A = Vue.extend({
  53. data: function () {
  54. return { a: 1 }
  55. },
  56. watch: {
  57. a: spy
  58. },
  59. created: function () {
  60. this.a = 2
  61. }
  62. })
  63. new Vue({
  64. extends: A
  65. })
  66. waitForUpdate(() => {
  67. expect(spy).toHaveBeenCalledWith(2, 1)
  68. }).then(done)
  69. })
  70. }
  71. })