Skip to content

Commit

Permalink
test: rewrite all tests because of deprecated lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed Jan 30, 2025
1 parent ca9e9e8 commit e35ef7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions __tests__/JSONSchemaViewer/__snapshots__/error.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JSONSchemaViewer states Can render error when something bad happens 1`] = `
<DocumentFragment>
<div>
Something bad happens : Resolver error
</div>
</DocumentFragment>
`;
15 changes: 11 additions & 4 deletions __tests__/JSONSchemaViewer/error.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from "react";
import { expect, test, describe, jest } from "@jest/globals";
import { render, screen } from "@testing-library/react";
import { render, act } from "@testing-library/react";
import JSONSchemaViewer from "../../src/theme/JSONSchemaViewer/index";

import type { RenderResult } from "@testing-library/react";
import type { JSONSchema } from "../../src/theme/JSONSchemaViewer/types";

jest.mock("@stoplight/json-ref-resolver", () => {
Expand All @@ -13,10 +15,15 @@ jest.mock("@stoplight/json-ref-resolver", () => {

describe("JSONSchemaViewer states", () => {
test("Can render error when something bad happens", async () => {
const fakeSchema3: JSONSchema = { type: "object" };
const fakeSchema: JSONSchema = { type: "object" }
let result: RenderResult | null = null;

render(<JSONSchemaViewer schema={fakeSchema3} />);
// Render the component within act
await act(async () => {
result = render(<JSONSchemaViewer schema={fakeSchema} />);
});

expect(await screen.findByText(/error/i)).toBeInTheDocument();
// Capture the snapshot
expect(result!.asFragment()).toMatchSnapshot();
});
});

0 comments on commit e35ef7f

Please sign in to comment.