From 4c81df28d88b48c5f6671d2e183cfb30723f7073 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Mon, 18 May 2020 10:59:11 +0200 Subject: [PATCH 1/7] Replaced getByTestId with fixed version --- src/helpers/findByAPI.js | 4 ++-- src/helpers/getByAPI.js | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/helpers/findByAPI.js b/src/helpers/findByAPI.js index 7b773979b..ea4fb1a7a 100644 --- a/src/helpers/findByAPI.js +++ b/src/helpers/findByAPI.js @@ -1,7 +1,7 @@ // @flow import waitForElement from '../waitForElement'; import { - fixedGetByTestId, + getByTestId, getAllByTestId, getByText, getAllByText, @@ -31,7 +31,7 @@ const makeFindQuery = ( export const findByTestId = (instance: ReactTestInstance) => ( testId: string, waitForOptions: WaitForOptions = {} -) => makeFindQuery(instance, fixedGetByTestId, testId, waitForOptions); +) => makeFindQuery(instance, getByTestId, testId, waitForOptions); export const findAllByTestId = (instance: ReactTestInstance) => ( testId: string, diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js index 052d3d560..cc6079607 100644 --- a/src/helpers/getByAPI.js +++ b/src/helpers/getByAPI.js @@ -149,15 +149,6 @@ export const getByProps = (instance: ReactTestInstance, warnFn?: Function) => }; export const getByTestId = (instance: ReactTestInstance) => - function getByTestIdFn(testID: string) { - try { - return instance.findByProps({ testID }); - } catch (error) { - throw new ErrorWithStack(prepareErrorMessage(error), getByTestIdFn); - } - }; - -export const fixedGetByTestId = (instance: ReactTestInstance) => function getByTestIdFn(testID: string) { try { const results = getAllByTestId(instance)(testID); From a961937b1acbd44b56f552b9cb17bd6ce31bcda5 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Mon, 18 May 2020 11:14:02 +0200 Subject: [PATCH 2/7] Added tests --- src/__tests__/getByApi.test.js | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/__tests__/getByApi.test.js diff --git a/src/__tests__/getByApi.test.js b/src/__tests__/getByApi.test.js new file mode 100644 index 000000000..a7d1f3fb3 --- /dev/null +++ b/src/__tests__/getByApi.test.js @@ -0,0 +1,40 @@ +// @flow +import React from 'react'; +import { View, Text, TextInput, Button } from 'react-native'; +import { render } from '..'; + +const options = { timeout: 10 }; // Short timeout so that this test runs quickly + +const MyComponent = () => { + return My Component; +}; + +test('byTestId returns only native elements', () => { + const { + getByTestId, + getAllByTestId, + queryByTestId, + queryAllByTestId, + } = render( + + Text + + +