import Vue from 'vue'

describe('Global API: extend', () => {
  it('should correctly merge options', () => {
    const Test = Vue.extend({
      name: 'test',
      a: 1,
      b: 2
    })
    expect(Test.options.a).toBe(1)
    expect(Test.options.b).toBe(2)
    expect(Test.super).toBe(Vue)
    const t = new Test({
      a: 2
    })
    expect(t.$options.a).toBe(2)
    expect(t.$options.b).toBe(2)
    // inheritance
    const Test2 = Test.extend({
      a: 2
    })
    expect(Test2.options.a).toBe(2)
    expect(Test2.options.b).toBe(2)
    const t2 = new Test2({
      a: 3
    })
    expect(t2.$options.a).toBe(3)
    expect(t2.$options.b).toBe(2)
  })

  it('should warn invalid names', () => {
    Vue.extend({ name: '123' })
    expect('Invalid component name: "123"').toHaveBeenWarned()
    Vue.extend({ name: '_fesf' })
    expect('Invalid component name: "_fesf"').toHaveBeenWarned()
    Vue.extend({ name: 'Some App' })
    expect('Invalid component name: "Some App"').toHaveBeenWarned()
  })

  it('should work when used as components', () => {
    const foo = Vue.extend({
      template: '<span>foo</span>'
    })
    const bar = Vue.extend({
      template: '<span>bar</span>'
    })
    const vm = new Vue({
      template: '<div><foo></foo><bar></bar></div>',
      components: { foo, bar }
    }).$mount()
    expect(vm.$el.innerHTML).toBe('<span>foo</span><span>bar</span>')
  })
})

@@ -1394,12 +1394,1196 @@
 %3E')%0A  %7D)
+%0A%0A  it('should merge lifecycle hooks', () =%3E %7B%0A    const calls = %5B%5D%0A    const A = Vue.extend(%7B%0A      created () %7B%0A        calls.push(1)%0A      %7D%0A    %7D)%0A    const B = A.extend(%7B%0A      created () %7B%0A        calls.push(2)%0A      %7D%0A    %7D)%0A    new B(%7B%0A      created () %7B%0A        calls.push(3)%0A      %7D%0A    %7D)%0A    expect(calls).toEqual(%5B1, 2, 3%5D)%0A  %7D)%0A%0A  it('should merge methods', () =%3E %7B%0A    const A = Vue.extend(%7B%0A      methods: %7B%0A        a () %7B return this.n %7D%0A      %7D%0A    %7D)%0A    const B = A.extend(%7B%0A      methods: %7B%0A        b () %7B return this.n + 1 %7D%0A      %7D%0A    %7D)%0A    const b = new B(%7B%0A      data: %7B n: 0 %7D,%0A      methods: %7B%0A        c () %7B return this.n + 2 %7D%0A      %7D%0A    %7D)%0A    expect(b.a()).toBe(0)%0A    expect(b.b()).toBe(1)%0A    expect(b.c()).toBe(2)%0A  %7D)%0A%0A  it('should merge assets', () =%3E %7B%0A    const A = Vue.extend(%7B%0A      components: %7B%0A        aa: %7B%0A          template: '%3Cdiv%3EA%3C/div%3E'%0A        %7D%0A      %7D%0A    %7D)%0A    const B = A.extend(%7B%0A      components: %7B%0A        bb: %7B%0A          template: '%3Cdiv%3EB%3C/div%3E'%0A        %7D%0A      %7D%0A    %7D)%0A    const b = new B(%7B%0A      template: '%3Cdiv%3E%3Caa%3E%3C/aa%3E%3Cbb%3E%3C/bb%3E%3C/div%3E'%0A    %7D).$mount()%0A    expect(b.$el.innerHTML).toBe('%3Cdiv%3EA%3C/div%3E%3Cdiv%3EB%3C/div%3E')%0A  %7D)
 %0A%7D)%0A

improve Vue.extend tests