test(vnode): partial tests for vnode creation (#116)
This commit is contained in:
parent
19c65a61ea
commit
b107401e71
@ -1,17 +1,111 @@
|
|||||||
|
import { createVNode } from '@vue/runtime-test'
|
||||||
|
import { ShapeFlags } from '@vue/runtime-core'
|
||||||
|
|
||||||
describe('vnode', () => {
|
describe('vnode', () => {
|
||||||
test.todo('create with just tag')
|
test('create with just tag', () => {
|
||||||
|
const vnode = createVNode('p')
|
||||||
|
expect(vnode.type).toBe('p')
|
||||||
|
expect(vnode.props).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('create with tag and props')
|
test('create with tag and props', () => {
|
||||||
|
const vnode = createVNode('p', {})
|
||||||
|
expect(vnode.type).toBe('p')
|
||||||
|
expect(vnode.props).toMatchObject({})
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('create with tag, props and children')
|
test('create with tag, props and children', () => {
|
||||||
|
const vnode = createVNode('p', {}, ['foo'])
|
||||||
|
expect(vnode.type).toBe('p')
|
||||||
|
expect(vnode.props).toMatchObject({})
|
||||||
|
expect(vnode.children).toMatchObject(['foo'])
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('create with 0 as props')
|
test('create with 0 as props', () => {
|
||||||
|
const vnode = createVNode('p', null)
|
||||||
|
expect(vnode.type).toBe('p')
|
||||||
|
expect(vnode.props).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('class normalization')
|
describe('class normalization', () => {
|
||||||
|
test('string', () => {
|
||||||
|
const vnode = createVNode('p', { class: 'foo baz' })
|
||||||
|
expect(vnode.props).toMatchObject({ class: 'foo baz' })
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('style normalization')
|
test('array<string>', () => {
|
||||||
|
const vnode = createVNode('p', { class: ['foo', 'baz'] })
|
||||||
|
expect(vnode.props).toMatchObject({ class: 'foo baz' })
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('children normalization')
|
test('array<object>', () => {
|
||||||
|
const vnode = createVNode('p', {
|
||||||
|
class: [{ foo: 'foo' }, { baz: 'baz' }]
|
||||||
|
})
|
||||||
|
expect(vnode.props).toMatchObject({ class: 'foo baz' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('object', () => {
|
||||||
|
const vnode = createVNode('p', { class: { foo: 'foo', baz: 'baz' } })
|
||||||
|
expect(vnode.props).toMatchObject({ class: 'foo baz' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('style normalization', () => {
|
||||||
|
test('array', () => {
|
||||||
|
const vnode = createVNode('p', {
|
||||||
|
style: [{ foo: 'foo' }, { baz: 'baz' }]
|
||||||
|
})
|
||||||
|
expect(vnode.props).toMatchObject({ style: { foo: 'foo', baz: 'baz' } })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('object', () => {
|
||||||
|
const vnode = createVNode('p', { style: { foo: 'foo', baz: 'baz' } })
|
||||||
|
expect(vnode.props).toMatchObject({ style: { foo: 'foo', baz: 'baz' } })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('children normalization', () => {
|
||||||
|
const nop = jest.fn
|
||||||
|
|
||||||
|
test('null', () => {
|
||||||
|
const vnode = createVNode('p', null, null)
|
||||||
|
expect(vnode.children).toBe(null)
|
||||||
|
expect(vnode.shapeFlag).toBe(ShapeFlags.ELEMENT)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('array', () => {
|
||||||
|
const vnode = createVNode('p', null, ['foo'])
|
||||||
|
expect(vnode.children).toMatchObject(['foo'])
|
||||||
|
expect(vnode.shapeFlag).toBe(
|
||||||
|
ShapeFlags.ELEMENT + ShapeFlags.ARRAY_CHILDREN
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('object', () => {
|
||||||
|
const vnode = createVNode('p', null, { foo: 'foo' })
|
||||||
|
expect(vnode.children).toMatchObject({ foo: 'foo' })
|
||||||
|
expect(vnode.shapeFlag).toBe(
|
||||||
|
ShapeFlags.ELEMENT + ShapeFlags.SLOTS_CHILDREN
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('function', () => {
|
||||||
|
const vnode = createVNode('p', null, nop)
|
||||||
|
expect(vnode.children).toMatchObject({ default: nop })
|
||||||
|
expect(vnode.shapeFlag).toBe(
|
||||||
|
ShapeFlags.ELEMENT + ShapeFlags.SLOTS_CHILDREN
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('string', () => {
|
||||||
|
const vnode = createVNode('p', null, 'foo')
|
||||||
|
expect(vnode.children).toBe('foo')
|
||||||
|
expect(vnode.shapeFlag).toBe(
|
||||||
|
ShapeFlags.ELEMENT + ShapeFlags.TEXT_CHILDREN
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test.todo('normalizeVNode')
|
test.todo('normalizeVNode')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user