parent.spec.ts 789 B

12345678910111213141516171819202122232425262728
  1. import Vue from 'vue'
  2. describe('Options parent', () => {
  3. it('should work', () => {
  4. const parent = new Vue({
  5. render() {}
  6. }).$mount()
  7. const child = new Vue({
  8. parent: parent,
  9. render() {}
  10. }).$mount()
  11. // this option is straight-forward
  12. // it should register 'parent' as a $parent for 'child'
  13. // and push 'child' to $children array on 'parent'
  14. expect(child.$options.parent).toBeDefined()
  15. expect(child.$options.parent).toEqual(parent)
  16. expect(child.$parent).toBeDefined()
  17. expect(child.$parent).toEqual(parent)
  18. expect(parent.$children).toContain(child)
  19. // destroy 'child' and check if it was removed from 'parent' $children
  20. child.$destroy()
  21. expect(parent.$children.length).toEqual(0)
  22. parent.$destroy()
  23. })
  24. })