test: assert vnode invalid key warning for NaN

This commit is contained in:
Evan You 2020-07-08 11:47:01 -04:00
parent 4b5ce8b456
commit 00f6031fbf

View File

@ -11,12 +11,14 @@ import {
transformVNodeArgs transformVNodeArgs
} from '../src/vnode' } from '../src/vnode'
import { Data } from '../src/component' import { Data } from '../src/component'
import { ShapeFlags, PatchFlags } from '@vue/shared' import { ShapeFlags, PatchFlags, mockWarn } from '@vue/shared'
import { h, reactive, isReactive } from '../src' import { h, reactive, isReactive } from '../src'
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test' import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
import { setCurrentRenderingInstance } from '../src/componentRenderUtils' import { setCurrentRenderingInstance } from '../src/componentRenderUtils'
describe('vnode', () => { describe('vnode', () => {
mockWarn()
test('create with just tag', () => { test('create with just tag', () => {
const vnode = createVNode('p') const vnode = createVNode('p')
expect(vnode.type).toBe('p') expect(vnode.type).toBe('p')
@ -62,6 +64,7 @@ describe('vnode', () => {
} }
expect(createVNode('div').key).toBe(null) expect(createVNode('div').key).toBe(null)
expect(createVNode('div', { key: undefined }).key).toBe(null) expect(createVNode('div', { key: undefined }).key).toBe(null)
expect(`VNode created with invalid key (NaN)`).toHaveBeenWarned()
}) })
test('create with class component', () => { test('create with class component', () => {