diff --git a/src/__tests__/__snapshots__/render.test.js.snap b/src/__tests__/__snapshots__/render.test.js.snap index 11881c3e8..13462ca90 100644 --- a/src/__tests__/__snapshots__/render.test.js.snap +++ b/src/__tests__/__snapshots__/render.test.js.snap @@ -20,12 +20,26 @@ exports[`debug 1`] = ` /> + + + + + + + + + + { render() { @@ -67,7 +69,10 @@ class Banana extends React.Component { testID="bananaChef" placeholder={PLACEHOLDER_CHEF} value={INPUT_CHEF} + defaultValue={DEFAULT_INPUT_CHEF} /> + + Change freshness! @@ -201,6 +206,18 @@ test('getByDisplayValue, queryByDisplayValue', () => { expect(() => queryByDisplayValue(/fresh/i)).toThrow('Expected 1 but found 2'); }); +test('getByDisplayValue, queryByDisplayValue get element by default value only when value is undefined', () => { + const { getByDisplayValue, queryByDisplayValue } = render(); + expect(() => getByDisplayValue(DEFAULT_INPUT_CHEF)).toThrow(); + expect(queryByDisplayValue(DEFAULT_INPUT_CHEF)).toBeNull(); + + expect(() => getByDisplayValue('hello')).toThrow(); + expect(queryByDisplayValue('hello')).toBeNull(); + + expect(getByDisplayValue(DEFAULT_INPUT_CUSTOMER)).toBeTruthy(); + expect(queryByDisplayValue(DEFAULT_INPUT_CUSTOMER)).toBeTruthy(); +}); + test('getAllByDisplayValue, queryAllByDisplayValue', () => { const { getAllByDisplayValue, queryAllByDisplayValue } = render(); const inputs = getAllByDisplayValue(/fresh/i); diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js index 9f6a0d5c6..41e74bdd5 100644 --- a/src/helpers/getByAPI.js +++ b/src/helpers/getByAPI.js @@ -107,11 +107,13 @@ const getTextInputNodeByPlaceholderText = (node, placeholder) => { const getTextInputNodeByDisplayValue = (node, value) => { try { const { TextInput } = require('react-native'); + const nodeValue = + node.props.value !== undefined + ? node.props.value + : node.props.defaultValue; return ( filterNodeByType(node, TextInput) && - (typeof value === 'string' - ? value === node.props.value - : value.test(node.props.value)) + (typeof value === 'string' ? value === nodeValue : value.test(nodeValue)) ); } catch (error) { throw createLibraryNotSupportedError(error);