Skip to content

Commit 1f4c06c

Browse files
committed
Add tests for invalid height payloads
Extend useAutoHeight tests to cover invalid payload cases: a prefixed but non-numeric payload ('__RN_SIZED_WV__:not-a-number') to exercise the isFinite branch, and a direct negative number (-10) to exercise the numericValue <= 0 branch. Both assertions verify that requestAnimationFrame is not called and the height remains unchanged, preventing regressions for malformed or out-of-range payloads.
1 parent 5a7c875 commit 1f4c06c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/__tests__/useAutoHeight.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ describe('useAutoHeight', () => {
150150
expect(requestAnimationFrameMock).not.toHaveBeenCalled();
151151
expect(latest.height).toBe(initialHeight);
152152

153+
// Prefixed but non-numeric payload also passes the prefix gate and must
154+
// still be rejected by the numeric validator (covers the isFinite branch).
155+
act(() => {
156+
latest.setHeightFromPayload('__RN_SIZED_WV__:not-a-number');
157+
});
158+
159+
expect(requestAnimationFrameMock).not.toHaveBeenCalled();
160+
expect(latest.height).toBe(initialHeight);
161+
162+
// Direct negative number payload exercises the numericValue <= 0 branch.
163+
act(() => {
164+
latest.setHeightFromPayload(-10);
165+
});
166+
167+
expect(requestAnimationFrameMock).not.toHaveBeenCalled();
168+
expect(latest.height).toBe(initialHeight);
169+
153170
act(() => {
154171
latest.setHeightFromPayload(initialHeight + 1);
155172
});

0 commit comments

Comments
 (0)