shlink-web-client/test/common/services/ImageDownloader.test.ts

26 lines
835 B
TypeScript
Raw Normal View History

import { Mock } from 'ts-mockery';
2023-02-18 12:40:37 +03:00
import type { HttpClient } from '../../../src/common/services/HttpClient';
2023-02-18 13:11:01 +03:00
import { ImageDownloader } from '../../../src/common/services/ImageDownloader';
2022-07-16 11:52:45 +03:00
import { windowMock } from '../../__mocks__/Window.mock';
2021-09-19 11:57:36 +03:00
describe('ImageDownloader', () => {
const fetchBlob = jest.fn();
const httpClient = Mock.of<HttpClient>({ fetchBlob });
2021-09-19 11:57:36 +03:00
let imageDownloader: ImageDownloader;
beforeEach(() => {
jest.clearAllMocks();
(global as any).URL = { createObjectURL: () => '' };
imageDownloader = new ImageDownloader(httpClient, windowMock);
2021-09-19 11:57:36 +03:00
});
it('calls URL with response type blob', async () => {
fetchBlob.mockResolvedValue(new Blob());
2021-09-19 11:57:36 +03:00
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
expect(fetchBlob).toHaveBeenCalledWith('/foo/bar.png');
2021-09-19 11:57:36 +03:00
});
});