generated from rdilweb/template-docusaurus-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable users to translate loading & error messages
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`JSONSchemaViewer states Can render error when something bad happens 1`] = ` | ||
<div> | ||
Something bad happens : Resolver error | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
|
||
// For typings autocomplete whatever your IDE | ||
import { expect, test, describe, jest } from "@jest/globals" | ||
|
||
import { create, act } from "react-test-renderer" | ||
|
||
import JSONSchemaViewer from "../../src/theme/JSONSchemaViewer/index"; | ||
|
||
// Type to prevent creating invalid mocks | ||
import type { JSONSchema } from "../../src/theme/JSONSchemaViewer/types" | ||
|
||
// Type for react-test-renderer | ||
import type { ReactTestRenderer } from "react-test-renderer" | ||
|
||
jest.mock('@stoplight/json-ref-resolver', () => { | ||
const resolve = jest.fn<() => Promise<JSONSchema>>().mockRejectedValue(new Error('Resolver error')); | ||
return { | ||
Resolver: jest.fn(() => ({ resolve })) | ||
}; | ||
}); | ||
|
||
describe("JSONSchemaViewer states", () => { | ||
|
||
test("Can render error when something bad happens", async () => { | ||
const fakeSchema3 : JSONSchema = { "type": "object" } | ||
|
||
// render the component | ||
let root: ReactTestRenderer | undefined | ||
await act(async () => { | ||
root = create(<JSONSchemaViewer schema={fakeSchema3} />) | ||
}) | ||
|
||
// make assertions on root | ||
expect(root?.toJSON()).toMatchSnapshot() | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters