1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/app-desktop/integration-tests/util/getImageSourceSize.ts

22 lines
706 B
TypeScript
Raw Normal View History

import { Locator } from '@playwright/test';
const getImageSourceSize = async (imageLocator: Locator) => {
// Use state: 'attached' -- we don't need the image to be on the screen (just present
// in the DOM).
await imageLocator.waitFor({ state: 'attached' });
// We load a copy of the image to avoid returning an overriden width set with
// .width = some_number
return await imageLocator.evaluate((originalImage: HTMLImageElement) => {
return new Promise<[number, number]>(resolve => {
const testImage = new Image();
testImage.onload = () => {
resolve([testImage.width, testImage.height]);
};
testImage.src = originalImage.src;
});
});
};
export default getImageSourceSize;