test: wip tests for inheritance and mixins
This commit is contained in:
parent
2f936a0dfe
commit
05fcfa0782
44
packages/core/__tests__/inheritance.spec.ts
Normal file
44
packages/core/__tests__/inheritance.spec.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { Component, createInstance } from '@vue/renderer-test'
|
||||||
|
|
||||||
|
describe('class inheritance', () => {
|
||||||
|
it('should merge data', () => {
|
||||||
|
class Base extends Component {
|
||||||
|
foo = 1
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
bar: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Child extends Base {
|
||||||
|
foo: number
|
||||||
|
bar: number
|
||||||
|
baz: number
|
||||||
|
qux: number = 4
|
||||||
|
|
||||||
|
data(): any {
|
||||||
|
return {
|
||||||
|
baz: 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const child = createInstance(Child)
|
||||||
|
|
||||||
|
expect(child.foo).toBe(1)
|
||||||
|
expect(child.bar).toBe(2)
|
||||||
|
expect(child.baz).toBe(3)
|
||||||
|
expect(child.qux).toBe(4)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should merge props', () => {})
|
||||||
|
|
||||||
|
it('should merge lifecycle hooks', () => {})
|
||||||
|
|
||||||
|
it('should merge watchers', () => {})
|
||||||
|
|
||||||
|
it('should inherit methods', () => {})
|
||||||
|
|
||||||
|
it('should inherit computed properties', () => {})
|
||||||
|
})
|
7
packages/core/__tests__/mixins.spec.ts
Normal file
7
packages/core/__tests__/mixins.spec.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
describe('mixins', () => {
|
||||||
|
it('should work with classes', () => {})
|
||||||
|
|
||||||
|
it('should work with objects', () => {})
|
||||||
|
|
||||||
|
it('should work with a mix of objects and classes', () => {})
|
||||||
|
})
|
@ -1,4 +1,10 @@
|
|||||||
import { createRenderer, VNode, Component } from '@vue/core'
|
import {
|
||||||
|
h,
|
||||||
|
createRenderer,
|
||||||
|
VNode,
|
||||||
|
Component,
|
||||||
|
createComponentInstance
|
||||||
|
} from '@vue/core'
|
||||||
import { nodeOps, TestElement } from './nodeOps'
|
import { nodeOps, TestElement } from './nodeOps'
|
||||||
import { patchData } from './patchData'
|
import { patchData } from './patchData'
|
||||||
|
|
||||||
@ -13,6 +19,20 @@ type publicRender = (
|
|||||||
) => Component | null
|
) => Component | null
|
||||||
export const render = _render as publicRender
|
export const render = _render as publicRender
|
||||||
|
|
||||||
|
export function createInstance<T extends Component>(
|
||||||
|
Class: new () => T,
|
||||||
|
props?: any
|
||||||
|
): T {
|
||||||
|
return createComponentInstance(h(Class, props)).$proxy as any
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderIntsance<T extends Component>(
|
||||||
|
Class: new () => T,
|
||||||
|
props?: any
|
||||||
|
): T {
|
||||||
|
return render(h(Class, props), nodeOps.createElement('div')) as any
|
||||||
|
}
|
||||||
|
|
||||||
export { serialize } from './serialize'
|
export { serialize } from './serialize'
|
||||||
export * from './nodeOps'
|
export * from './nodeOps'
|
||||||
export * from '@vue/core'
|
export * from '@vue/core'
|
||||||
|
Loading…
Reference in New Issue
Block a user