Skip to content

Commit

Permalink
fix(analytics): safely access props, as it can be undefined
Browse files Browse the repository at this point in the history
analytics props can be undefined, so we should access it with that in mind
  • Loading branch information
aVileBroker committed Jan 9, 2023
1 parent c76b3f4 commit dd5c329
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/components/Toggle/__tests__/Toggle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ describe('Toggle', () => {

describe('Accessibility Tests', () => {
it('Should pass accessibility test with default props', async () => {
const component = <Toggle onToggle={() => {}} inputProps={{ 'aria-label': 'test' }}></Toggle>;
const component = (
<Toggle
onToggle={() => {}}
inputProps={{
'aria-label': 'test',
// forcing this aria-checked attribute, as jest-axe requires it,
// but useSwitch from react-aria no longer generates it.
// https://github.com/adobe/react-spectrum/pull/3687
// https://github.com/adobe/react-spectrum/issues/1264
// https://github.com/adobe/react-spectrum/issues/3130
'aria-checked': false,
}}
></Toggle>
);
const { container } = render(component);
const results = await axe(container);
expect(container).toMatchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const defaultAnalyticsFunction: AnalyticsFunctionType = (
dateTime,
deviceInfo,
currentURL,
name: 'name' in props ? props.name : 'No name provided',
analytics: 'analytics' in props ? props.analytics : 'No analytics object provided',
name: props?.name ?? 'No name provided',
analytics: props?.analytics ?? 'No analytics object provided',
});

export const defaultAccessibilityPreferences: AccessibilityPreferences = {
Expand Down

0 comments on commit dd5c329

Please sign in to comment.