Skip to content

Commit

Permalink
feat(toHaveStyle): handle when the prop style is undefined (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunohkbx authored Jul 26, 2020
1 parent 60791a0 commit db5ccb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/__tests__/to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ describe('.toHaveStyle', () => {
expect(() => expect(container).toHaveStyle({ fontWeight: 'bold' })).toThrowError();
expect(() => expect(container).not.toHaveStyle({ color: 'black' })).toThrowError();
});

test('handles when the style prop is undefined', () => {
const { getByTestId } = render(
<View testID="container">
<Text>Hello World</Text>
</View>,
);

const container = getByTestId('container');

expect(container).not.toHaveStyle({ fontWeight: 'bold' });
});
});
2 changes: 1 addition & 1 deletion src/to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function expectedDiff(expected, elementStyles) {
export function toHaveStyle(element, style) {
checkReactElement(element, toHaveStyle, this);

const elementStyle = element.props.style;
const elementStyle = element.props.style ?? {};

const expected = Array.isArray(style) ? mergeAllStyles(style) : style;
const received = Array.isArray(elementStyle) ? mergeAllStyles(elementStyle) : elementStyle;
Expand Down

0 comments on commit db5ccb3

Please sign in to comment.