generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Allows onError callback to not use event handler #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
fixtures/components/error-boundary/error-boundary/index.tsx
This file contains hidden or 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,23 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import * as React from 'react'; | ||
| import { NonCancelableEventHandler } from '../../internal/events'; | ||
|
|
||
| export interface ErrorBoundaryProps { | ||
| /** | ||
| * React content. | ||
| */ | ||
| children: React.ReactNode; | ||
| /** | ||
| * A special callback that fires when an error is captured. | ||
| */ | ||
| onError: (error: Error, errorInfo: React.ErrorInfo) => void; | ||
| /** | ||
| * A callback that fires when the user clicks on the refresh button. | ||
| */ | ||
| onRefresh?: NonCancelableEventHandler; | ||
| } | ||
|
|
||
| export default function ErrorBoundary({ children }: ErrorBoundaryProps): JSX.Element { | ||
| return <div>{children}</div>; | ||
| } |
This file contains hidden or 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 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "rootDir": "." | ||
| }, | ||
| "include": ["./**/*.tsx"] | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,66 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`Error boundary > should have correct properties definitions 1`] = ` | ||
| [ | ||
| { | ||
| "dashCaseName": "error-boundary", | ||
| "description": undefined, | ||
| "events": [ | ||
| { | ||
| "cancelable": false, | ||
| "deprecatedTag": undefined, | ||
| "description": "A callback that fires when the user clicks on the refresh button.", | ||
| "detailInlineType": undefined, | ||
| "detailType": undefined, | ||
| "name": "onRefresh", | ||
| "systemTags": undefined, | ||
| }, | ||
| ], | ||
| "functions": [], | ||
| "name": "ErrorBoundary", | ||
| "properties": [ | ||
| { | ||
| "analyticsTag": undefined, | ||
| "defaultValue": undefined, | ||
| "deprecatedTag": undefined, | ||
| "description": "A special callback that fires when an error is captured.", | ||
| "i18nTag": undefined, | ||
| "inlineType": { | ||
| "name": "(error: Error, errorInfo: React.ErrorInfo) => void", | ||
| "parameters": [ | ||
| { | ||
| "name": "error", | ||
| "type": "Error", | ||
| }, | ||
| { | ||
| "name": "errorInfo", | ||
| "type": "React.ErrorInfo", | ||
| }, | ||
| ], | ||
| "returnType": "void", | ||
| "type": "function", | ||
| }, | ||
| "name": "onError", | ||
| "optional": false, | ||
| "systemTags": undefined, | ||
| "type": "(error: Error, errorInfo: React.ErrorInfo) => void", | ||
| "visualRefreshTag": undefined, | ||
| }, | ||
| ], | ||
| "regions": [ | ||
| { | ||
| "deprecatedTag": undefined, | ||
| "description": "React content.", | ||
| "displayName": undefined, | ||
| "i18nTag": undefined, | ||
| "isDefault": true, | ||
| "name": "children", | ||
| "systemTags": undefined, | ||
| "visualRefreshTag": undefined, | ||
| }, | ||
| ], | ||
| "releaseStatus": "stable", | ||
| "systemTags": undefined, | ||
| }, | ||
| ] | ||
| `; |
This file contains hidden or 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,12 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, test } from 'vitest'; | ||
| import { buildProject } from './test-helpers'; | ||
|
|
||
| describe('Error boundary', () => { | ||
| test('should have correct properties definitions', () => { | ||
| const result = buildProject('error-boundary'); | ||
| expect(result).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding a test for the onError behavior. You could trigger a condition that causes onError to be called and then verify it with toHaveBeenCalledWith
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here validate that the onError is added to the generated documentation (validated with the snapshot test), but the actual error boundary implementation is here: cloudscape-design/components#3736, and it does include the coverage on the onError behaviour.