diff --git a/docs/api/matchers.md b/docs/api/matchers.md index 0b626dbc..5039282d 100644 --- a/docs/api/matchers.md +++ b/docs/api/matchers.md @@ -1,5 +1,5 @@ --- -sidebar_position: 2 +sidebar_position: 3 --- # Matchers @@ -10,13 +10,14 @@ This custom matcher will try to find and compare the baseline screenshot by usin #### Example -```js {7} +```js title="__tests__/App.owl.tsx" import { takeScreenshot } from 'react-native-owl'; describe('App.tsx', () => { it('takes a screenshot of the first screen', async () => { const screen = await takeScreenshot('homescreen'); + // highlight-next-line expect(screen).toMatchBaseline(); }); }); diff --git a/docs/api/methods.md b/docs/api/methods.md index 16155815..b91be8d4 100644 --- a/docs/api/methods.md +++ b/docs/api/methods.md @@ -10,11 +10,12 @@ Grabs a screenshot from the simulator and stores it under `latest` screenshots(i #### Example -```js {5} +```js title="__tests__/App.owl.tsx" import { takeScreenshot } from 'react-native-owl'; describe('App.tsx', () => { it('takes a screenshot of the first screen', async () => { + // highlight-next-line const screen = await takeScreenshot('homescreen'); expect(screen).toMatchBaseline(); @@ -25,3 +26,212 @@ describe('App.tsx', () => { The first time this test is run, or when run with the `--update` flag, the screenshot will be stored at `./owl/baseline/ios/homescreen.png` (or `/android/` is testing on Android). On subsequent test runs, the screenshot will be stored at `./owl/current/ios/homescreen.png`. + +### toExist(testID: string) + +Waits for an element to exist where its `testID` prop matches the methods `testID` argument. + +If there is no matching element, it will retry for 10 seconds before throwing an Error. + +#### Example + +```js title="App.tsx" +... +const [isLoaded, setIsLoaded] = React.useState(false); + +React.useEffect(() => { + setTimeout(() => { + setIsLoaded(true); + }, 1000); +}, []); + +<> + {isLoaded && ( + + )} + +... +``` + +```js title="__tests__/App.owl.tsx" +import { toExist, takeScreenshot } from 'react-native-owl'; + +describe('App.tsx', () => { + it('waits for an element, then takes a screenshot', async () => { + // highlight-next-line + await toExist('textInput'); + + const screen = await takeScreenshot('textInputExists'); + + expect(screen).toMatchBaseline(); + }); +}); +``` + +### press(testID: string) + +Calls the `onPress` prop callback of the element where its `testID` prop matches the methods `testID` argument. + +If there is no matching element, it will retry for 10 seconds before throwing an Error. + +The element must have a `onPress` prop, or an Error will be thrown. + +#### Example + +```js title="App.tsx" +... +