Skip to content

Commit f558c59

Browse files
committed
replacing errors thrown with console.warn
1 parent 4a91c39 commit f558c59

File tree

12 files changed

+52
-28
lines changed

12 files changed

+52
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Currently, this repo is in Prerelease. When it is released, this project will ad
2020
- Updates the `viewport` preview options in Storybook to align with the Reservoir breakpoints.
2121
- Updates the Storybook font styles.
2222
- Updates the docs for the `Template` component.
23+
- Replaces the error thrown with a console.warn for the `Breadcrumbs`, `Heading`, and `Image` components.
2324

2425
## Prerelease
2526

@@ -35,7 +36,6 @@ Currently, this repo is in Prerelease. When it is released, this project will ad
3536
- Updated the `"filter"` variant of `TagSet` to remove tag button wrapper when `isDismissible` and `onClick` are false.
3637
- Updates `Image` to include 'fourByOne' and 'twoByThree' aspect ratio options.
3738

38-
3939
## 3.5.4 (February 13, 2025)
4040

4141
### Adds

src/components/Breadcrumbs/Breadcrumbs.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import Link from "../Link/Link";
99

1010
# Breadcrumbs
1111

12-
| Component Version | DS Version |
13-
| ----------------- | ---------- |
14-
| Added | `0.0.3` |
15-
| Latest | `3.5.3` |
12+
| Component Version | DS Version |
13+
| ----------------- | ------------ |
14+
| Added | `0.0.3` |
15+
| Latest | `Prerelease` |
1616

1717
## Table of Contents
1818

src/components/Breadcrumbs/Breadcrumbs.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ describe("Breadcrumbs", () => {
7676
expect(container.querySelector(".breadcrumbs-icon")).toBeInTheDocument();
7777
});
7878

79-
it("Throws error when nothing is passed into Breadcrumb", () => {
80-
expect(() => render(<Breadcrumbs breadcrumbsData={[]} />)).toThrowError(
79+
it("logs a warning when nothing is passed into Breadcrumb", () => {
80+
const warn = jest.spyOn(console, "warn");
81+
render(<Breadcrumbs breadcrumbsData={[]} />);
82+
83+
expect(warn).toHaveBeenCalledWith(
8184
"NYPL Reservoir Breadcrumbs: No data was passed to the `breadcrumbsData` prop."
8285
);
8386
});

src/components/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const Breadcrumbs: ChakraComponent<
155155
} = props;
156156

157157
if (!breadcrumbsData || breadcrumbsData.length === 0) {
158-
throw new Error(
158+
console.warn(
159159
"NYPL Reservoir Breadcrumbs: No data was passed to the `breadcrumbsData` prop."
160160
);
161161
}

src/components/Breadcrumbs/breadcrumbsChangelogData.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import { ChangelogData } from "../../utils/ComponentChangelogTable";
1010

1111
export const changelogData: ChangelogData[] = [
12+
{
13+
date: "Prerelease",
14+
version: "Prerelease",
15+
type: "Update",
16+
affects: ["Functionality"],
17+
notes: ["Replaces the error thrown with a console.warn."],
18+
},
1219
{
1320
date: "2025-01-30",
1421
version: "3.5.3",

src/components/Heading/Heading.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { changelogData } from "./headingChangelogData";
1212
| Component Version | DS Version |
1313
| ----------------- | ---------- |
1414
| Added | `0.0.4` |
15-
| Latest | `3.5.3` |
15+
| Latest | `Prelease` |
1616

1717
## Table of Contents
1818

src/components/Heading/Heading.test.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,25 @@ describe("Heading", () => {
9595
);
9696
});
9797

98-
it("throws error when neither child nor text is passed", () => {
99-
expect(() => render(<Heading id="h1" level="h1" />)).toThrow(
98+
it("logs a warning when neither child nor text is passed", () => {
99+
const warn = jest.spyOn(console, "warn");
100+
render(<Heading id="h1" level="h1" />);
101+
expect(warn).toHaveBeenCalledWith(
100102
"NYPL Reservoir Heading: No children or value was passed to the `text` prop."
101103
);
102104
});
103105

104-
it("throws error when heading with many children is passed", () => {
105-
expect(() =>
106-
render(
107-
<Heading id="h1" level="h4">
108-
<span>too</span>
109-
<span>many</span>
110-
</Heading>
111-
)
112-
).toThrow("NYPL Reservoir Heading: Only pass one child into Heading.");
106+
it("logs a warning when heading with many children is passed", () => {
107+
const warn = jest.spyOn(console, "warn");
108+
render(
109+
<Heading id="h1" level="h4">
110+
<span>too</span>
111+
<span>many</span>
112+
</Heading>
113+
);
114+
expect(warn).toHaveBeenCalledWith(
115+
"NYPL Reservoir Heading: Only pass one child into Heading."
116+
);
113117
});
114118

115119
it("uses custom display size", () => {

src/components/Heading/Heading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ export const Heading: ChakraComponent<
138138
const asHeading: any = finalLevel;
139139

140140
if (!props.children && !text) {
141-
throw new Error(
141+
console.warn(
142142
"NYPL Reservoir Heading: No children or value was passed to the `text` prop."
143143
);
144144
}
145145

146146
if (React.Children.count(props.children) > 1) {
147147
// Catching the error because React's error isn't as helpful.
148-
throw new Error(
148+
console.warn(
149149
"NYPL Reservoir Heading: Only pass one child into Heading."
150150
);
151151
}

src/components/Heading/headingChangelogData.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import { ChangelogData } from "../../utils/ComponentChangelogTable";
1010

1111
export const changelogData: ChangelogData[] = [
12+
{
13+
date: "Prerelease",
14+
version: "Prerelease",
15+
type: "Update",
16+
affects: ["Functionality"],
17+
notes: ["Replaces the error thrown with a console.warn."],
18+
},
1219
{
1320
date: "2025-01-30",
1421
version: "3.5.3",

src/components/Image/Image.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ describe("Image", () => {
9393
expect(screen.getByText("credit")).toBeInTheDocument();
9494
});
9595

96-
it("throws error when alt text is too long", () => {
97-
expect(() =>
98-
render(<Image src="test.png" alt={tooManyChars} />)
99-
).toThrowError(
96+
it("logs an error when alt text is too long", () => {
97+
const warn = jest.spyOn(console, "warn");
98+
render(<Image src="test.png" alt={tooManyChars} />);
99+
expect(warn).toHaveBeenCalledWith(
100100
"NYPL Reservoir Image: Alt text must be less than 300 characters."
101101
);
102102
});

0 commit comments

Comments
 (0)