|
|
|
@ -1,3 +1,5 @@ |
|
|
|
import type { ApiComponentProps } from '../types'; |
|
|
|
|
|
|
|
import { mount } from '@vue/test-utils'; |
|
|
|
import { defineComponent, h, markRaw, nextTick, ref } from 'vue'; |
|
|
|
|
|
|
|
@ -128,4 +130,28 @@ describe('api-component.vue', () => { |
|
|
|
expect(handleUpdate).toHaveBeenCalledWith('selected'); |
|
|
|
expect(input.props('modelValue')).toBe('selected'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('fetches when the api is provided after mount', async () => { |
|
|
|
const api = vi |
|
|
|
.fn() |
|
|
|
.mockResolvedValue([{ label: 'Loaded', value: 'loaded' }]); |
|
|
|
const apiRef = ref<ApiComponentProps['api']>(); |
|
|
|
const Harness = defineComponent({ |
|
|
|
setup() { |
|
|
|
return () => |
|
|
|
h(ApiComponent, { |
|
|
|
api: apiRef.value, |
|
|
|
component: markRaw(ModelValueInput), |
|
|
|
}); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
mount(Harness); |
|
|
|
expect(api).not.toHaveBeenCalled(); |
|
|
|
|
|
|
|
apiRef.value = api; |
|
|
|
await nextTick(); |
|
|
|
|
|
|
|
expect(api).toHaveBeenCalledTimes(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|