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', () => {
let events: any[] = []
let events: DebuggerEvent[] = []
let dummy
const onTrigger = jest.fn((e: DebuggerEvent) => {
events.push(e)

View File

@ -258,4 +258,29 @@ describe('api: provide/inject', () => {
await nextTick()
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: {
count: ref(0)
},
array: [1, 2, 3]
array: [1, 2, 3],
map: new Map([['a', 1], ['b', 2]])
})
let dummy
let arr
watch(
() => state,
state => {
dummy = state.nested.count
arr = state.array[2]
dummy = [state.nested.count, state.array[0], state.map.get('a')]
},
{ deep: true }
)
await nextTick()
expect(dummy).toBe(0)
expect(arr).toBe(3)
expect(dummy).toEqual([0, 1, 1])
state.nested.count++
await nextTick()
expect(dummy).toBe(1)
expect(arr).toBe(3)
expect(dummy).toEqual([1, 1, 1])
// nested array mutation
state.array[2] = 4
state.array[0] = 2
await nextTick()
expect(dummy).toBe(1)
expect(arr).toBe(4)
expect(dummy).toEqual([1, 2, 1])
// nested map mutation
state.map.set('a', 2)
await nextTick()
expect(dummy).toEqual([1, 2, 2])
})
it('lazy', async () => {

View File

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

View File

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