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

26 lines
830 B
TypeScript
Raw Normal View History

import { Mock } from 'ts-mockery';
2021-09-19 11:57:36 +03:00
import { ImageDownloader } from '../../../src/common/services/ImageDownloader';
import { HttpClient } from '../../../src/common/services/HttpClient';
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
});
});