Skip to content

Commit bfe1ab0

Browse files
committed
fix: add coverage for onClick
1 parent 2ebfa6e commit bfe1ab0

File tree

3 files changed

+308
-0
lines changed

3 files changed

+308
-0
lines changed

package-lock.json

Lines changed: 285 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"devDependencies": {
3030
"@open-rpc/meta-schema": "^1.11.0",
31+
"@testing-library/react": "^11.2.2",
3132
"@types/jest": "^24.0.11",
3233
"@types/json-schema": "^7.0.3",
3334
"@types/lodash": "^4.14.123",

src/ExamplePairings/ExamplePairings.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import ExamplePairings from "./ExamplePairings";
44
import examples from "@open-rpc/examples";
55
import refParser from "json-schema-ref-parser";
66
import { OpenrpcDocument, ExamplePairingObject } from "@open-rpc/meta-schema";
7+
import {
8+
cleanup,
9+
fireEvent,
10+
render,
11+
} from "@testing-library/react";
712

813
it("renders without crashing", () => {
914
const div = document.createElement("div");
@@ -147,3 +152,20 @@ it("renders examples with only schema examples and no method", async () => {
147152
, div);
148153
ReactDOM.unmountComponentAtNode(div);
149154
});
155+
156+
it("renders examples and can switch between them", async () => {
157+
const simpleMath = await refParser.dereference(examples.simpleMath) as OpenrpcDocument;
158+
const { getByText } = render(
159+
<ExamplePairings
160+
method={simpleMath.methods[0]}
161+
examples={simpleMath.methods[0].examples as ExamplePairingObject[]
162+
} />,
163+
);
164+
const node = getByText("simpleMathAdditionTwo");
165+
fireEvent.click(node);
166+
const secondExampleMenuItem = getByText("simpleMathAdditionFour");
167+
fireEvent.click(secondExampleMenuItem);
168+
const example8 = getByText("8");
169+
expect(example8).toBeDefined();
170+
cleanup();
171+
});

0 commit comments

Comments
 (0)