3

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);
  });
});

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.