Skip to content

Commit 5a8608e

Browse files
committed
fix: add null safety checks for terminal scroll refs in tests
- Add requestAnimationFrame mock in Hero tests - Add null checks before accessing scrollHeight in TerminalPopup - Prevents 'Cannot read properties of null' error in CI/CD - All 278 tests now passing including Hero component tests
1 parent 883d029 commit 5a8608e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/components/TerminalPopup.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,10 @@ const TerminalPopup = ({
623623
useEffect(() => {
624624
if (terminalBodyRef.current) {
625625
const scrollToBottom = () => {
626-
terminalBodyRef.current!.scrollTop =
627-
terminalBodyRef.current!.scrollHeight;
626+
if (terminalBodyRef.current) {
627+
terminalBodyRef.current.scrollTop =
628+
terminalBodyRef.current.scrollHeight;
629+
}
628630
};
629631

630632
// Use requestAnimationFrame for smooth scrolling
@@ -636,10 +638,12 @@ const TerminalPopup = ({
636638
useEffect(() => {
637639
if (terminalBodyRef.current && isTyping) {
638640
const scrollToBottom = () => {
639-
terminalBodyRef.current!.scrollTo({
640-
top: terminalBodyRef.current!.scrollHeight,
641-
behavior: "smooth",
642-
});
641+
if (terminalBodyRef.current) {
642+
terminalBodyRef.current.scrollTo({
643+
top: terminalBodyRef.current.scrollHeight,
644+
behavior: "smooth",
645+
});
646+
}
643647
};
644648

645649
// Small delay to ensure content is rendered

src/components/__tests__/Hero.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ describe("Hero Component", () => {
3535

3636
beforeEach(() => {
3737
jest.clearAllMocks();
38+
// Mock requestAnimationFrame for tests
39+
jest.spyOn(window, "requestAnimationFrame").mockImplementation((cb) => {
40+
cb(0);
41+
return 0;
42+
});
43+
});
44+
45+
afterEach(() => {
46+
jest.restoreAllMocks();
3847
});
3948

4049
it("should render hero section", () => {

0 commit comments

Comments
 (0)