I have a problem with the unit test. I try to check useQuery that has been called with toHaveBeenCalledTimes() but no luck it always returns zero time. I'm not sure which part I mistake.
export default defineComponent({
name: 'MyComponent',
setup() {
const {
result: dataPagination
} = useQuery(GET_DATA_PAGINATION, {
skip: pagination.skip,
take: pagination.take,
});
// another part...
},
});
And spec.ts just like this
const mockUseQuery = jest.fn();
jest.mock('@vue/apollo-composable', () => ({
useQuery: () => ({
result: mockUseQuery
})
}));
describe('StoreType.vue', () => {
let wrapper = null;
beforeEach(() => {
config = {
global: {
...config.global,
},
};
wrapper = mount(MyComponent, { ...config,
shallow: true
});
});
afterEach(() => {
wrapper.unmount();
jest.resetAllMocks();
});
it('Fetch all store type by pagination', async() => {
expect(wrapper.exists()).toBe(true);
expect(mockQuery).toHaveBeenCalledTimes(1);
});
});