test: coverage

This commit is contained in:
Evan You 2019-08-27 14:42:05 -04:00
parent 7ecdc79d5e
commit 62e07a1b7e
5 changed files with 40 additions and 13 deletions

View File

@ -570,7 +570,7 @@ describe('reactivity/effect', () => {
}) })
it('events: onTrigger', () => { it('events: onTrigger', () => {
let events: any[] = [] let events: DebuggerEvent[] = []
let dummy let dummy
const onTrigger = jest.fn((e: DebuggerEvent) => { const onTrigger = jest.fn((e: DebuggerEvent) => {
events.push(e) events.push(e)

View File

@ -258,4 +258,29 @@ describe('api: provide/inject', () => {
await nextTick() await nextTick()
expect(serialize(root)).toBe(`<div>2</div>`) expect(serialize(root)).toBe(`<div>2</div>`)
}) })
it('should warn unfound', () => {
const Provider = {
setup() {
return () => h(Middle)
}
}
const Middle = {
render: () => h(Consumer)
}
const Consumer = {
setup() {
const foo = inject('foo')
expect(foo).toBeUndefined()
return () => foo
}
}
const root = nodeOps.createElement('div')
render(h(Provider), root)
expect(serialize(root)).toBe(`<div><!----></div>`)
expect(`injection "foo" not found.`).toHaveBeenWarned()
})
}) })

View File

@ -260,34 +260,35 @@ describe('api: watch', () => {
nested: { nested: {
count: ref(0) count: ref(0)
}, },
array: [1, 2, 3] array: [1, 2, 3],
map: new Map([['a', 1], ['b', 2]])
}) })
let dummy let dummy
let arr
watch( watch(
() => state, () => state,
state => { state => {
dummy = state.nested.count dummy = [state.nested.count, state.array[0], state.map.get('a')]
arr = state.array[2]
}, },
{ deep: true } { deep: true }
) )
await nextTick() await nextTick()
expect(dummy).toBe(0) expect(dummy).toEqual([0, 1, 1])
expect(arr).toBe(3)
state.nested.count++ state.nested.count++
await nextTick() await nextTick()
expect(dummy).toBe(1) expect(dummy).toEqual([1, 1, 1])
expect(arr).toBe(3)
// nested array mutation // nested array mutation
state.array[2] = 4 state.array[0] = 2
await nextTick() await nextTick()
expect(dummy).toBe(1) expect(dummy).toEqual([1, 2, 1])
expect(arr).toBe(4)
// nested map mutation
state.map.set('a', 2)
await nextTick()
expect(dummy).toEqual([1, 2, 2])
}) })
it('lazy', async () => { it('lazy', async () => {

View File

@ -35,7 +35,7 @@ export function inject(key: InjectionKey<any> | string, defaultValue?: any) {
} else if (defaultValue !== undefined) { } else if (defaultValue !== undefined) {
return defaultValue return defaultValue
} else if (__DEV__) { } else if (__DEV__) {
warn(`injection ${key} not found.`) warn(`injection "${key}" not found.`)
} }
} }
} }

View File

@ -1,3 +1,4 @@
export function warn(...args: any[]) { export function warn(...args: any[]) {
// TODO // TODO
console.warn(...args)
} }