@envive-ai/react-hooks 0.3.19-alpha-marlo-1 → 0.3.19-alpha-marlo-2
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
|
@@ -447,15 +447,11 @@ describe('AmplitudeProvider - React Context Integration', () => {
|
|
|
447
447
|
});
|
|
448
448
|
|
|
449
449
|
describe('useAmplitude hook', () => {
|
|
450
|
-
it('should
|
|
451
|
-
|
|
452
|
-
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
450
|
+
it('should return safe no-op defaults when used outside provider', () => {
|
|
451
|
+
render(<MockAmplitudeComponent />);
|
|
453
452
|
|
|
454
|
-
expect(()
|
|
455
|
-
|
|
456
|
-
}).toThrow('useAmplitude must be used within AmplitudeProvider');
|
|
457
|
-
|
|
458
|
-
consoleError.mockRestore();
|
|
453
|
+
expect(screen.getByTestId('amplitude-component')).toBeInTheDocument();
|
|
454
|
+
expect(screen.getByTestId('is-ready').textContent).toBe('false');
|
|
459
455
|
});
|
|
460
456
|
|
|
461
457
|
it('should provide amplitude context when used within provider', async () => {
|
|
@@ -26,7 +26,13 @@ interface AmplitudeContextType {
|
|
|
26
26
|
setSupplementalDefaultProps: (props: Record<string, unknown>) => void;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const defaultAmplitudeContext: AmplitudeContextType = {
|
|
30
|
+
trackEvent: async () => {},
|
|
31
|
+
isReady: false,
|
|
32
|
+
setSupplementalDefaultProps: () => {},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const AmplitudeContext = createContext<AmplitudeContextType>(defaultAmplitudeContext);
|
|
30
36
|
|
|
31
37
|
export const AmplitudeProvider: React.FC<{
|
|
32
38
|
externalAmplitudeService?: AmplitudeService;
|
|
@@ -122,9 +128,5 @@ export const AmplitudeProvider: React.FC<{
|
|
|
122
128
|
};
|
|
123
129
|
|
|
124
130
|
export const useAmplitude = () => {
|
|
125
|
-
|
|
126
|
-
if (!context) {
|
|
127
|
-
throw new Error('useAmplitude must be used within AmplitudeProvider');
|
|
128
|
-
}
|
|
129
|
-
return context;
|
|
131
|
+
return useContext(AmplitudeContext);
|
|
130
132
|
};
|