@servicetitan/error-boundary 40.2.2 → 40.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/error-boundary",
|
|
3
|
-
"version": "40.
|
|
3
|
+
"version": "40.3.0",
|
|
4
4
|
"description": "Implementation of React error boundary mechanism",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/error-boundary",
|
|
6
6
|
"repository": {
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
-
"src"
|
|
16
|
+
"src",
|
|
17
|
+
"!**/__tests__",
|
|
18
|
+
"!**/__mocks__",
|
|
19
|
+
"!**/__snapshots__",
|
|
20
|
+
"!**/*.test.*"
|
|
17
21
|
],
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"@servicetitan/log-service": "40.
|
|
20
|
-
"@servicetitan/react-ioc": "40.
|
|
23
|
+
"@servicetitan/log-service": "40.3.0",
|
|
24
|
+
"@servicetitan/react-ioc": "40.3.0",
|
|
21
25
|
"@testing-library/dom": "^10.4.2",
|
|
22
26
|
"@testing-library/jest-dom": "^7.0.1",
|
|
23
27
|
"@testing-library/react": "^16.3.3",
|
|
@@ -25,8 +29,8 @@
|
|
|
25
29
|
"react": "~18.3.1"
|
|
26
30
|
},
|
|
27
31
|
"peerDependencies": {
|
|
28
|
-
"@servicetitan/log-service": "40.
|
|
29
|
-
"@servicetitan/react-ioc": "40.
|
|
32
|
+
"@servicetitan/log-service": "40.3.0",
|
|
33
|
+
"@servicetitan/react-ioc": "40.3.0",
|
|
30
34
|
"react": ">=17.0.2"
|
|
31
35
|
},
|
|
32
36
|
"publishConfig": {
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { Log } from '@servicetitan/log-service';
|
|
2
|
-
import { Provider } from '@servicetitan/react-ioc';
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
import { FC, ReactNode } from 'react';
|
|
6
|
-
import { ErrorBoundary, ErrorBoundaryProps, FallbackProps } from '../error-boundary';
|
|
7
|
-
|
|
8
|
-
describe(`[error-boundary] ${ErrorBoundary.name}`, () => {
|
|
9
|
-
const childContent = 'foo';
|
|
10
|
-
|
|
11
|
-
let props: ErrorBoundaryProps;
|
|
12
|
-
let children: ReactNode;
|
|
13
|
-
let log: Log;
|
|
14
|
-
|
|
15
|
-
const ChildComponent: FC = () => <div>{childContent}</div>;
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
children = <ChildComponent />;
|
|
19
|
-
props = { moduleName: 'Foo' };
|
|
20
|
-
log = { error: jest.fn() } as any;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const subject = () =>
|
|
24
|
-
render(
|
|
25
|
-
<Provider singletons={[{ provide: Log, useValue: log }]}>
|
|
26
|
-
<ErrorBoundary {...props}>{children}</ErrorBoundary>
|
|
27
|
-
</Provider>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
test('renders children', () => {
|
|
31
|
-
subject();
|
|
32
|
-
|
|
33
|
-
expect(screen.getByText(childContent)).toBeInTheDocument();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('when an error occurs', () => {
|
|
37
|
-
let throwError: boolean;
|
|
38
|
-
|
|
39
|
-
const error = new Error('Oops');
|
|
40
|
-
|
|
41
|
-
const ErrorComponent: FC = () => {
|
|
42
|
-
if (throwError) {
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
jest.spyOn(console, 'error').mockImplementation(jest.fn()); // suppress console errors
|
|
50
|
-
children = <ErrorComponent />;
|
|
51
|
-
throwError = true;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('renders default fallback', () => {
|
|
55
|
-
subject();
|
|
56
|
-
|
|
57
|
-
expect(screen.getByText('Something went wrong')).toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('logs the error', () => {
|
|
61
|
-
subject();
|
|
62
|
-
|
|
63
|
-
expect(log.error).toHaveBeenCalledWith(
|
|
64
|
-
{
|
|
65
|
-
error,
|
|
66
|
-
data: { Module: props.moduleName },
|
|
67
|
-
message: error.message,
|
|
68
|
-
},
|
|
69
|
-
{ skipConsole: true }
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('with a custom fallback', () => {
|
|
74
|
-
let fallbackProps: FallbackProps;
|
|
75
|
-
|
|
76
|
-
const fallbackMessage = 'Custom fallback message';
|
|
77
|
-
|
|
78
|
-
const Fallback: FC<FallbackProps> = props => {
|
|
79
|
-
fallbackProps = props;
|
|
80
|
-
return <div>{fallbackMessage}</div>;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
beforeEach(() => (props.fallback = Fallback));
|
|
84
|
-
|
|
85
|
-
test('renders custom fallback', () => {
|
|
86
|
-
subject();
|
|
87
|
-
|
|
88
|
-
expect(screen.getByText(fallbackMessage)).toBeInTheDocument();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('onRefresh removes the error', async () => {
|
|
92
|
-
subject();
|
|
93
|
-
await screen.findByText(fallbackMessage);
|
|
94
|
-
|
|
95
|
-
throwError = false;
|
|
96
|
-
fallbackProps.onRefresh!();
|
|
97
|
-
|
|
98
|
-
await waitFor(() => {
|
|
99
|
-
expect(screen.queryByText(fallbackMessage)).not.toBeInTheDocument();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('with custom error data', () => {
|
|
105
|
-
const when = Date();
|
|
106
|
-
|
|
107
|
-
const customDataCallback: ErrorBoundaryProps['getErrorData'] = (error: Error) => {
|
|
108
|
-
return { when, errorName: error.name };
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
beforeEach(() => (props.getErrorData = customDataCallback));
|
|
112
|
-
|
|
113
|
-
test('adds custom data to the log', () => {
|
|
114
|
-
subject();
|
|
115
|
-
|
|
116
|
-
expect(log.error).toHaveBeenLastCalledWith(
|
|
117
|
-
expect.objectContaining({
|
|
118
|
-
data: { Module: props.moduleName, ...customDataCallback(error) },
|
|
119
|
-
}),
|
|
120
|
-
{ skipConsole: true }
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|