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

23 lines
667 B
TypeScript
Raw Normal View History

2021-09-19 11:57:36 +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 fetch = jest.fn();
2021-09-19 11:57:36 +03:00
let imageDownloader: ImageDownloader;
beforeEach(() => {
jest.clearAllMocks();
(global as any).URL = { createObjectURL: () => '' };
imageDownloader = new ImageDownloader(fetch, windowMock);
2021-09-19 11:57:36 +03:00
});
it('calls URL with response type blob', async () => {
fetch.mockResolvedValue({ blob: () => new Blob() });
2021-09-19 11:57:36 +03:00
await imageDownloader.saveImage('/foo/bar.png', 'my-image.png');
expect(fetch).toHaveBeenCalledWith('/foo/bar.png');
2021-09-19 11:57:36 +03:00
});
});