Skip to content

Commit 0dbda71

Browse files
authored
fix(toHaveProp): check null values (#68)
1 parent 9480002 commit 0dbda71

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/__tests__/to-have-prop.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react';
22
import { Button, Text, View } from 'react-native';
33
import { render } from '@testing-library/react-native';
44

5-
test('.toHaveProp', () => {
5+
describe('.toHaveProp', () => {
66
const { queryByTestId } = render(
7-
<View>
7+
<View accessibilityLabel={null} testID="view">
88
<Text allowFontScaling={false} testID="text">
99
text
1010
</Text>
@@ -33,4 +33,8 @@ test('.toHaveProp', () => {
3333
expect(() =>
3434
expect(queryByTestId('text')).toHaveProp('allowFontScaling', 'wrongValue'),
3535
).toThrowError();
36+
37+
it('checks null values', () => {
38+
expect(queryByTestId('view')).toHaveProp('accessibilityLabel', null);
39+
});
3640
});

src/to-have-prop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { equals, isNil, not } from 'ramda';
1+
import { equals } from 'ramda';
22
import { matcherHint, stringify, printExpected } from 'jest-matcher-utils';
33
import { checkReactElement, getMessage } from './utils';
44

@@ -18,7 +18,7 @@ export function toHaveProp(element, name, expectedValue) {
1818
const prop = element.props[name];
1919

2020
const isDefined = expectedValue !== undefined;
21-
const hasProp = not(isNil(prop));
21+
const hasProp = name in element.props;
2222

2323
return {
2424
pass: isDefined ? hasProp && equals(prop, expectedValue) : hasProp,

0 commit comments

Comments
 (0)