mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-24 18:08:19 +03:00
25 lines
830 B
TypeScript
25 lines
830 B
TypeScript
import { Mock } from 'ts-mockery';
|
|
import { ImageDownloader } from '../../../src/common/services/ImageDownloader';
|
|
import { HttpClient } from '../../../src/common/services/HttpClient';
|
|
import { windowMock } from '../../__mocks__/Window.mock';
|
|
|
|
describe('ImageDownloader', () => {
|
|
const fetchBlob = jest.fn();
|
|
const httpClient = Mock.of<HttpClient>({ fetchBlob });
|
|
let imageDownloader: ImageDownloader;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
(global as any).URL = { createObjectURL: () => '' };
|
|
|
|
imageDownloader = new ImageDownloader(httpClient, windowMock);
|
|
});
|
|
|
|
it('calls URL with response type blob', async () => {
|
|
fetchBlob.mockResolvedValue(new Blob());
|
|
|
|
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
|
|
|
|
expect(fetchBlob).toHaveBeenCalledWith('/foo/bar.png');
|
|
});
|
|
});
|