Skip to content

Commit 978cc2a

Browse files
committed
test: add counter-regression test for #524
1 parent 7bd5045 commit 978cc2a

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import RenderHTML from '../RenderHTML';
3+
import { render } from '@testing-library/react-native';
4+
5+
/**
6+
* https://github.com/meliorence/react-native-render-html/issues/524
7+
**/
8+
describe('RenderHTML component', () => {
9+
describe('should pass regression regarding percent width', () => {
10+
it('dimensions should not be derived from aspect ratio', async () => {
11+
const renderersProps = {
12+
img: {
13+
enableExperimentalPercentWidth: true
14+
}
15+
};
16+
const { findByTestId } = render(
17+
<RenderHTML
18+
debug={false}
19+
contentWidth={300}
20+
renderersProps={renderersProps}
21+
source={{
22+
html: '<img style="width:100%" src="https://img.com/1920x1080" width="800" height="400"/>'
23+
}}
24+
/>
25+
);
26+
const img = await findByTestId('image-success');
27+
expect(img).toHaveStyle({
28+
width: 300,
29+
height: 400
30+
});
31+
});
32+
});
33+
});

packages/render-html/src/elements/__tests__/IMGElement.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ describe('IMGElement', () => {
313313
const image = await findByTestId('image-success');
314314
expect(image).toBeTruthy();
315315
expect(image).toHaveStyle({
316-
width: 640
316+
width: 640,
317+
height: 360
317318
});
318319
});
319-
it('should support strings for width and height which can be parsed to floats', async () => {
320+
it('should support strings for width and height which can be parsed to numbers', async () => {
320321
const source = { uri: 'http://via.placeholder.com/640x360' };
321322
const style = {
322323
width: '50'
@@ -340,7 +341,7 @@ describe('IMGElement', () => {
340341
const { findByTestId } = render(
341342
<HTMLImgElement
342343
enableExperimentalPercentWidth
343-
contentWidth={250}
344+
contentWidth={contentWidth}
344345
{...style}
345346
source={source}
346347
/>

0 commit comments

Comments
 (0)