Skip to content

Commit

Permalink
Fixed EuiI8n hasPropName utility errors on null values (#3303)
Browse files Browse the repository at this point in the history
* added test with null value

* fixed i18n null value error

* cl
  • Loading branch information
ashikmeerankutty authored Apr 13, 2020
1 parent 9c688db commit 5e51f38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ No public interface changes since `22.5.0`.

**Bug Fixes**

- Fixed EuiI8n hasPropName utility errors on null values ([#3303](https://github.com/elastic/eui/pull/3303))
- Fixed the inline styles being overwritten by consumer-passed inline styles in EuiBadge ([#3284](https://github.com/elastic/eui/pull/3284))

## [`22.4.0`](https://github.com/elastic/eui/tree/v22.4.0)
Expand Down
16 changes: 16 additions & 0 deletions src/components/i18n/__snapshots__/i18n.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ exports[`EuiI18n default rendering rendering to dom renders a string with placeh
</EuiI18n>
`;

exports[`EuiI18n default rendering rendering to dom renders when value is null 1`] = `
<EuiI18n
default="{arg}"
token="test"
values={
Object {
"arg": null,
}
}
>
<Component
arg={null}
/>
</EuiI18n>
`;

exports[`EuiI18n reading values from context mappingFunc calls the mapping function with the source string 1`] = `
<EuiContext
i18n={
Expand Down
7 changes: 7 additions & 0 deletions src/components/i18n/i18n.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ describe('EuiI18n', () => {

expect(renderCallback).toHaveBeenCalledWith(values);
});

it('renders when value is null', () => {
const component = mount(
<EuiI18n token="test" default="{arg}" values={{ arg: null }} />
);
expect(component).toMatchSnapshot();
});
});

describe('render prop with single token', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/i18n/i18n_util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function isPrimitive(value: ReactChild) {
type Child = string | { propName: string } | ReactChild | undefined;

function hasPropName(child: Child): child is { propName: string } {
return typeof child === 'object' && child.hasOwnProperty('propName');
return child
? typeof child === 'object' && child.hasOwnProperty('propName')
: false;
}

/**
Expand Down

0 comments on commit 5e51f38

Please sign in to comment.