Przeglądaj źródła

also test mounted for child component

Evan You 10 lat temu
rodzic
commit
9adbe9c399

+ 1 - 0
src/core/instance/lifecycle.js

@@ -56,6 +56,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
     hydrating = false
     vm._isMounted = true
     // root instance, call mounted on self
+    // mounted is called for child components in its inserted hook
     if (vm.$root === vm) {
       callHook(vm, 'mounted')
     }

+ 1 - 1
test/helpers/to-equal.js

@@ -10,7 +10,7 @@ beforeEach(() => {
           const pass = isEqual(a, b)
           return {
             pass,
-            message: `Expected ${a}${pass ? ' ' : ' not '}to equal ${b}`
+            message: `Expected ${a} to equal ${b}`
           }
         }
       }

+ 19 - 0
test/unit/features/options/lifecycle.spec.js

@@ -74,6 +74,25 @@ describe('Options lifecyce hooks', () => {
       vm.$mount()
       expect(spy).toHaveBeenCalled()
     })
+
+    it('should mount child parent in correct order', () => {
+      const calls = []
+      new Vue({
+        template: '<test></test>',
+        mounted () {
+          calls.push('parent')
+        },
+        components: {
+          test: {
+            template: '<div></div>',
+            mounted () {
+              calls.push('child')
+            }
+          }
+        }
+      }).$mount()
+      expect(calls).toEqual(['child', 'parent'])
+    })
   })
 
   describe('beforeUpdate', () => {