Skip to content

Commit

Permalink
test: verify <PrismicText> throws error on invalid input
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed May 26, 2022
1 parent 2e4bab0 commit c21caf0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/PrismicText.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from "ava";
import * as React from "react";
import * as prismicT from "@prismicio/types";
import * as sinon from "sinon";

import { PrismicText } from "../src";

Expand Down Expand Up @@ -53,3 +54,19 @@ test("returns fallback when passed empty field", (t) => {
t.deepEqual(actualUndefined, expected);
t.deepEqual(actualEmpty, expected);
});

test("throws error if passed a string-based field (e.g. Key Text or Select)", (t) => {
// Used to supress logging the error in this test.
const consoleErrorStub = sinon.stub(console, "error");

t.throws(() =>
renderJSON(
<PrismicText
// @ts-expect-error - We are purposely not providing a correct field.
field="not a Rich Text field"
/>,
),
);

consoleErrorStub.restore();
});

0 comments on commit c21caf0

Please sign in to comment.