parent.spec.js 747 B

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