Fix regex in convertCSSToStyle, add test coverage (#21508)

This commit is contained in:
Ivana Huckova 2020-01-15 17:25:51 +01:00 committed by GitHub
parent a35b2ac463
commit dce4d184a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -33,4 +33,20 @@ describe('<LogMessageAnsi />', () => {
.text()
).toBe('ipsum');
});
it('renders string with ANSI codes with correctly converted css classnames', () => {
const value = 'Lorem Ipsum';
const wrapper = shallow(<LogMessageAnsi value={value} />);
expect(wrapper.find('span')).toHaveLength(1);
expect(
wrapper
.find('span')
.first()
.prop('style')
).toMatchObject(
expect.objectContaining({
fontWeight: expect.any(String),
})
);
});
});

View File

@ -15,7 +15,7 @@ function convertCSSToStyle(css: string): Style {
const match = line.match(/([^:\s]+)\s*:\s*(.+)/);
if (match && match[1] && match[2]) {
const key = match[1].replace(/-(a-z)/g, (_, character) => character.toUpperCase());
const key = match[1].replace(/-([a-z])/g, (_, character) => character.toUpperCase());
// @ts-ignore
accumulated[key] = match[2];
}