Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PrismicLink): do not warn about missing field properties if the Link field is empty #163

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(PrismicLink): do not warn about missing field properties if the L…
…ink field is empty
  • Loading branch information
angeloashmore committed Jul 30, 2022
commit 6db944e183b54187234e2a43165c450ca77f6f6c
6 changes: 2 additions & 4 deletions src/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ const _PrismicLink = <
)}`,
);
} else if (
!(
prismicH.isFilled.link(props.field) &&
("url" in props.field || "id" in props.field)
)
Object.keys(props.field).length > 1 &&
!("url" in props.field || "uid" in props.field || "id" in props.field)
) {
console.warn(
`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(
Expand Down
4 changes: 2 additions & 2 deletions test/PrismicLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ test.serial(
);

test.serial("warns if properties are missing from a given field", (t) => {
const field = { link_type: prismicT.LinkType.Web };
const field = { link_type: prismicT.LinkType.Web, target: "_blank" };

const consoleWarnStub = sinon.stub(console, "warn");

Expand All @@ -480,7 +480,7 @@ test.serial("does not warn if given field is empty", (t) => {

consoleWarnStub.restore();

t.true(consoleWarnStub.calledWithMatch("missing-link-properties"));
t.false(consoleWarnStub.called);
});

test.serial("warns if properties are missing from a given document", (t) => {
Expand Down