|
| 1 | +import type { Ref } from 'vue-demi' |
1 | 2 | import { computed, nextTick, ref } from 'vue-demi'
|
2 | 3 | import { promiseTimeout } from '@vueuse/shared'
|
3 |
| -import { describe, expect, it, vi } from 'vitest' |
| 4 | +import { describe, expect, expectTypeOf, it, vi } from 'vitest' |
4 | 5 | import { asyncComputed, computedAsync } from '.'
|
5 | 6 |
|
6 | 7 | describe('computed', () => {
|
@@ -37,6 +38,16 @@ describe('computedAsync', () => {
|
37 | 38 | expect(data.value).toBe('data')
|
38 | 39 | })
|
39 | 40 |
|
| 41 | + it('types are correct', async () => { |
| 42 | + const func = vi.fn(() => Promise.resolve('data')) |
| 43 | + |
| 44 | + const data1 = computedAsync(func) |
| 45 | + const data2 = computedAsync(func, 'initialState') |
| 46 | + |
| 47 | + expectTypeOf(data1).toEqualTypeOf<Ref<string | undefined>>() |
| 48 | + expectTypeOf(data2).toEqualTypeOf<Ref<string>>() |
| 49 | + }) |
| 50 | + |
40 | 51 | it('call onError when error is thrown', async () => {
|
41 | 52 | let errorMessage
|
42 | 53 | const func = vi.fn(async () => {
|
@@ -180,7 +191,7 @@ describe('computedAsync', () => {
|
180 | 191 | return Promise.resolve(result)
|
181 | 192 | })
|
182 | 193 | const other = computed(() => {
|
183 |
| - return double.value + 1 |
| 194 | + return (double.value ?? 0) + 1 |
184 | 195 | })
|
185 | 196 |
|
186 | 197 | expect(double.value).toBeUndefined()
|
|
0 commit comments