-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/use-sync-external-store-correctly
- Loading branch information
Showing
19 changed files
with
417 additions
and
141 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,6 @@ | ||
export class CustomError extends Error { | ||
constructor(...args: ConstructorParameters<ErrorConstructor>) { | ||
super(...args) | ||
console.error(...args) | ||
} | ||
} |
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,5 @@ | ||
export class CustomNotError { | ||
constructor(public message?: string) { | ||
console.log(message) | ||
} | ||
} |
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
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
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
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
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
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
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
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,38 @@ | ||
import { CustomError, CustomNotError } from '@suspensive/test-utils' | ||
import type { ComponentProps } from 'react' | ||
import { describe, expectTypeOf, it } from 'vitest' | ||
import { ErrorBoundary } from './ErrorBoundary' | ||
import type { ConstructorType } from './utility-types' | ||
|
||
describe('<ErrorBoundary/>', () => { | ||
it('should pass only boolean or ErrorConstructor or ShouldCatchCallback or ShouldCatch[]', () => { | ||
type ShouldCatchCallback = (error: Error) => boolean | ||
type ShouldCatch = boolean | ConstructorType<Error> | ShouldCatchCallback | ||
expectTypeOf<ComponentProps<typeof ErrorBoundary>['shouldCatch']>().toEqualTypeOf< | ||
undefined | ShouldCatch | [ShouldCatch, ...ShouldCatch[]] | ||
>() | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const ShouldCatchByMany = () => ( | ||
<ErrorBoundary | ||
shouldCatch={[ | ||
// @ts-expect-error CustomNotError should be new (...args) => Error | ||
CustomNotError, | ||
CustomError, | ||
(error) => error instanceof CustomError, | ||
Math.random() > 0.5, | ||
]} | ||
fallback={({ error }) => <>{error.message} of Child</>} | ||
></ErrorBoundary> | ||
) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const ShouldCatchByOne = () => ( | ||
<ErrorBoundary | ||
// @ts-expect-error CustomNotError should be new (...args) => Error | ||
shouldCatch={CustomNotError} | ||
fallback={({ error }) => <>{error.message} of Child</>} | ||
></ErrorBoundary> | ||
) | ||
}) | ||
}) |
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
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 @@ | ||
export type ConstructorType<TClass> = new (...args: any[]) => TClass |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type { PropsWithDevMode } from './PropsWithDevMode' | ||
export type { OmitKeyOf } from './OmitKeyOf' | ||
export type { ConstructorType } from './ConstructorType' |
Oops, something went wrong.