mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
chore: add links to more sample of code (#104)
* add links to more sample of code * Update API.md * Update API.md
This commit is contained in:
committed by
Michał Pierzchała
parent
af067d0712
commit
39d2e7c8d0
+11
-1
@@ -5,7 +5,9 @@ title: API
|
||||
|
||||
This page gathers public API of `react-native-testing-library` along with usage examples.
|
||||
|
||||
## `render`
|
||||
## `render`
|
||||
|
||||
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/render.test.js)
|
||||
|
||||
Defined as:
|
||||
|
||||
@@ -135,6 +137,8 @@ Get the rendered component JSON representation, e.g. for snapshot testing.
|
||||
|
||||
## `shallow`
|
||||
|
||||
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/shallow.test.js)
|
||||
|
||||
Shallowly renders given React component. Since it doesn't return helpers to query the output, it's mostly advised to used for snapshot testing (short snapshots are best for code reviewers).
|
||||
|
||||
```jsx
|
||||
@@ -148,6 +152,8 @@ test('Component has a structure', () => {
|
||||
|
||||
## `fireEvent`
|
||||
|
||||
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/fireEvent.test.js)
|
||||
|
||||
Invokes a given event handler (whether native or custom) on the element, bubbling to the root of the rendered tree. The three most common events (`press`, `changeText`, and `scroll`) have been aliased for convenience.
|
||||
|
||||
### `fireEvent: (element: ReactTestInstance, eventName: string, data?: *) => void`
|
||||
@@ -252,6 +258,8 @@ fireEvent.scroll(getByTestId('scroll-view'), eventData);
|
||||
|
||||
## `waitForElement`
|
||||
|
||||
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/waitForElement.test.js)
|
||||
|
||||
Defined as:
|
||||
|
||||
```jsx
|
||||
@@ -278,6 +286,8 @@ If you're using Jest's [Timer Mocks](https://jestjs.io/docs/en/timer-mocks#docsN
|
||||
|
||||
## `debug`
|
||||
|
||||
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/debug.test.js)
|
||||
|
||||
Log prettified shallowly rendered component or test instance (just like snapshot) to stdout.
|
||||
|
||||
```jsx
|
||||
|
||||
Reference in New Issue
Block a user