Skip to content

Commit

Permalink
fix(PrismicLink): do not warn about missing field properties if the L…
Browse files Browse the repository at this point in the history
…ink field is empty (#163)
  • Loading branch information
angeloashmore authored Jul 30, 2022
1 parent 5be1649 commit b138472
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
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

0 comments on commit b138472

Please sign in to comment.