Skip to content

Commit 1fb07d2

Browse files
committed
docs
1 parent 940c331 commit 1fb07d2

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ For Expo, follow the [localization docs](https://docs.expo.dev/distribution/app-
239239

240240
On Android, you have a choice between using the component API (regular React component) or an imperative api (think of something like `ReactNative.alert()`).
241241

242-
While the component API has the benefit of writing the same code on all platforms, to start we recommend using the imperative API on Android.
242+
While the component API has the benefit of writing the same code on all platforms, for start we recommend using the imperative API on Android.
243243

244244
The `params` is an object with the same properties as the component props documented in the next paragraph. (This is also because the component api internally uses the imperative one.)
245245

246-
```js
246+
```ts
247247
import { DateTimePickerAndroid } from '@react-native-community/datetimepicker';
248248

249249
DateTimePickerAndroid.open(params: AndroidNativeProps)
@@ -343,7 +343,7 @@ We strongly recommend avoiding this prop on android because of known issues in t
343343

344344
#### `timeZoneOffsetInSeconds` (`optional`, `Windows only`)
345345

346-
Allows changing of the time zone of the date picker. By default it uses the device's time zone.
346+
Allows changing of the time zone of the date picker. By default, it uses the device's time zone.
347347

348348
```js
349349
// UTC+1
@@ -416,7 +416,7 @@ Prefer localization as documented in [Localization note](#localization-note).
416416

417417
#### `is24Hour` (`optional`, `Windows and Android only`)
418418

419-
Allows changing of the time picker to a 24 hour format. By default, this value is decided automatcially based on the locale and other preferences.
419+
Allows changing of the time picker to a 24-hour format. By default, this value is decided automatically based on the locale and other preferences.
420420

421421
```js
422422
<RNDateTimePicker is24Hour={true} />
@@ -466,7 +466,7 @@ Sets style directly on picker component. By default, the picker height is determ
466466

467467
Please note that by default, picker's text color is controlled by the application theme (light / dark mode). In dark mode, text is white and in light mode, text is black.
468468

469-
This means that eg. if the device has dark mode turned on, and your screen background color is white, you will not see the picker. Please use the `Appearance` api to adjust the picker's background color so that it is visible, as we do in the [example App](/example/App.js).
469+
This means that e.g. if the device has dark mode turned on, and your screen background color is white, you will not see the picker. Please use the `Appearance` api to adjust the picker's background color so that it is visible, as we do in the [example App](/example/App.js).
470470
Alternatively, use the `themeVariant` prop or [opt-out from dark mode (discouraged)](https://stackoverflow.com/a/56546554/2070942).
471471

472472
```js
@@ -481,6 +481,14 @@ If true, the user won't be able to interact with the view.
481481

482482
Callback that is called when an error occurs inside the date picker native code (such as null activity).
483483

484+
## Testing with Jest
485+
486+
If you're rendering the picker component (using the react-native-testing-library or similar), you need to mock the native module:
487+
488+
```
489+
"setupFiles": ["./node_modules/@react-native-community/datetimepicker/jest/setup.js"]
490+
```
491+
484492
## Migration from the older components
485493

486494
Please see [migration.md](/docs/migration.md)
File renamed without changes.

test/userlandTestExamples.test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
*/
55
import React, {useState} from 'react';
66
import {Text, Button} from 'react-native';
7-
import RNDateTimePicker, {DateTimePickerAndroid} from '../src/index';
7+
// in your code, import from '@react-native-community/datetimepicker'
8+
import DateTimePicker, {DateTimePickerAndroid} from '../src/index';
89
import {render, fireEvent, waitFor} from '@testing-library/react-native';
910
import {createDateTimeSetEvtParams} from '../src/index';
10-
import {
11-
mockAndroidDialogDateChange,
12-
mockAndroidDialogDismissal,
13-
} from '../jest/mockEventTriggers';
11+
import {mockAndroidDialogDateChange, mockAndroidDialogDismissal} from '../jest';
1412

1513
function TestAppWithComponent() {
1614
const [date, setDate] = React.useState<?Date>();
1715

1816
return (
1917
<>
20-
<RNDateTimePicker
18+
<DateTimePicker
2119
value={new Date(0)}
2220
onChange={(evt, selectedDate) => {
2321
setDate(selectedDate);
@@ -62,24 +60,25 @@ const AppWithImperativePicker = () => {
6260
const renderPickerComponent = async () => {
6361
const utils = render(<TestAppWithComponent />);
6462

65-
await waitFor(() => utils.UNSAFE_getByType(RNDateTimePicker));
63+
await waitFor(() => utils.UNSAFE_getByType(DateTimePicker));
6664
return utils;
6765
};
66+
6867
describe('userland tests', () => {
69-
it('rendering RNDateTimePicker and calling fireEvent, triggers onChange (platform-agnostic)', async () => {
68+
it("rendering DateTimePicker and calling fireEvent triggers the picker's onChange callback (platform-agnostic)", async () => {
7069
const date = new Date(156e10);
7170

7271
const {UNSAFE_getByType, getByText} = await renderPickerComponent();
7372

7473
fireEvent(
75-
UNSAFE_getByType(RNDateTimePicker),
74+
UNSAFE_getByType(DateTimePicker),
7675
'onChange',
7776
...createDateTimeSetEvtParams(date),
7877
);
7978
getByText('1560000000');
8079
});
8180

82-
describe("when using android picker's imperative api, we can simulate", () => {
81+
describe('when using android imperative api, we can simulate', () => {
8382
it('the date being changed', async () => {
8483
const {getByText} = render(<AppWithImperativePicker />);
8584

0 commit comments

Comments
 (0)