[Vuejs]-Testing vue-filepond component

0👍

Ok, figured this out with some vitest mocking:

it('handles file uploads and emits upload event', async () => {
    const testBase64EncodedFile = 'base64EncodedFile';
    const wrapper = mount(ImageUpload, {
      props,
    });

    const fileMock = {
      getFileEncodeBase64String: vi.fn()
        .mockReturnValue(testBase64EncodedFile),
    };

    wrapper.vm.imageUploaderRef = {
      getFile: vi.fn()
        .mockReturnValue(fileMock),
    };

    await wrapper.vm.handleUpdateFiles();

    expect(wrapper.vm.encodedFile)
      .toBe(testBase64EncodedFile);
    expect(wrapper.emitted('upload')[0][0])
      .toBe(testBase64EncodedFile);
  });

Leave a comment