Граф коммитов

58 Коммитов

Автор SHA1 Сообщение Дата
Ramanpreet Nara 9db0050635 Fix Jest mocks
Summary: Since we started relying on NativeModules' getConstants() method to access constants, we need to update our jest mocks of these NativeModules, so that the tests still pass. I do that in this diff.

Reviewed By: fkgozali

Differential Revision: D13561376

fbshipit-source-id: eaef3de82d842fd97d04be741d55bdded73c6a11
2018-12-30 13:31:16 -08:00
ferrannp e8a6cb5e18 Android: Adding sendIntent on Linking module (#22302)
Summary:
This PR implements "Add a standardized way to send intents on Android" discussed in https://github.com/react-native-community/discussions-and-proposals/issues/34.
Pull Request resolved: https://github.com/facebook/react-native/pull/22302

Differential Revision: D13374186

Pulled By: cpojer

fbshipit-source-id: 2f0b9b9f46e99f382b6c35b1914e75df23a7fd74
2018-12-06 21:13:58 -08:00
Spencer Ahrens 6f34bc4016 Back out "reapply TextInput es6 conversion with fixes, attemps to fix"
Summary:
Back it out again. This time really not sure why this is breaking, but it seems to be production only. The error seems to be "RCTSinglelineTextInputView" was not found in the UIManager" but the relavent logic is not changed in this diff, just moved around, so unclear why it would trigger a failure.

Reverting to be safe. When we re-apply the diff, we'll need to test a full OTA to prod to verify the fix.

Reviewed By: blairvanderhoof

Differential Revision: D13108463

fbshipit-source-id: 5f877a0c1a08dc114ce45921d6d92bf619575977
2018-11-16 14:50:23 -08:00
Spencer Ahrens 9ea1295179 reapply TextInput es6 conversion with fixes, attemps to fix
Summary: D10515754 reapplied by backing out D12989604 and then fixed by manually forwarding the instance methods to the host function instead of using `forwardRef`. This also removes the need for the $flowFixMe.

Reviewed By: TheSavior

Differential Revision: D13048482

fbshipit-source-id: ff2447aff123e0960eddaef645f7dc976a426e14
2018-11-15 20:51:52 -08:00
Eli White f386f831d2 Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.

This was created by running:

```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```

Reviewed By: yungsters

Differential Revision: D12989604

fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:59:10 -08:00
Eli White 7e818aed9a Fixing TextInput related jest tests
Reviewed By: yungsters

Differential Revision: D10519823

fbshipit-source-id: 02368b670953a0275fa6495b0c73ef84403598cb
2018-11-07 18:44:40 -08:00
Michał Pierzchała 5e997f9d51 use requireActual and requireMock from jest instead of require (#21849)
Summary:
A while back Jest introduced `jest.requireActual` and `jest.requireMock` which are aliases to `require.requireActual` and `require.requireMock`. We believe that users should use official Jest API and are planning to deprecate the latter.
Pull Request resolved: https://github.com/facebook/react-native/pull/21849

Differential Revision: D10448849

Pulled By: TheSavior

fbshipit-source-id: 34fffde97f48c26098c74ee222a56d99071703a6
2018-10-18 15:32:15 -07:00
Andrew Chen (Eng) aac7c4d5d2 Refactor UIManager view manager accesses
Summary: Replaced each view manager access with a getViewManager() function call. This will later be used to lazily load view manager classes by allowing java to avoid sending the entire list of view managers to JS.

Reviewed By: QueryConnectionException

Differential Revision: D9695788

fbshipit-source-id: 949858aa2f0b0b00b68e260461ba8f1d085cf07f
2018-09-27 16:03:22 -07:00
Janic Duplessis 458d56c0a1 Remove global babelHelpers and regenerator (#21283)
Summary:
Follow up to 8932a9caa8

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: https://github.com/facebook/react-native/pull/21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
2018-09-26 10:03:05 -07:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
Eli White d2c27f5bff Remove view configs from JS
Summary: Apparently different apps have different implementations of view managers that support different props. This is a problem that we will need to address. Unfortunately, this means we can't have a static config defined in JS. We will need to find another approach to this problem.

Reviewed By: sahrens

Differential Revision: D9500178

fbshipit-source-id: b591559164fcf29f5fd43e13a0f2da15011491c6
2018-08-24 14:04:09 -07:00
Eli White 1329d18c6a Require that JS defined Component Attributes match Native ones in dev
Summary: As we move these configs to JS from native, until we have codegen that ensures everything stays up to date, this adds a dev mode check to ensure they are consistent.

Reviewed By: yungsters

Differential Revision: D9475011

fbshipit-source-id: 9d6f7b6c649229cae569d840eda3d5f7b7aa7cb2
2018-08-23 13:01:41 -07:00
Jan Kassens 7205232792 remove FbRelayNativeAdapter
Summary: Doesn't look like this is used anymore.

Reviewed By: schwink

Differential Revision: D9032481

fbshipit-source-id: c35b7db07c068b6238bacc25183a468c9d62661d
2018-07-27 13:37:12 -07:00
gengjiawen 4a2c560768 add missing jest mock in StatusBarManager
Summary:
fix issue https://github.com/facebook/react-native/issues/11701.

Pass current ci

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

<!--
  Required.
  Help reviewers and the release process by writing your own release notes. See below for an example.
-->

 [GENERAL] [BUGFIX] [JEST] - add missing jest mock in StatusBarManager

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes https://github.com/facebook/react-native/pull/19017

Differential Revision: D8014888

Pulled By: hramos

fbshipit-source-id: 1be29f9643cf0faa53ad64f79e11d48b654a97b3
2018-05-15 14:01:39 -07:00
Eli White 36fcbaa56d Prettier the rest of ReactNative
Reviewed By: yungsters

Differential Revision: D7974340

fbshipit-source-id: 5fe457a8a9be4bd360fc3af9acb5c1136b2be0d7
2018-05-11 13:52:30 -07:00
Tim Yung e708010d18 RN: Switch `Text` to `React.forwardRef`
Reviewed By: sahrens

Differential Revision: D7902262

fbshipit-source-id: 218f95cde6d77f21d9362a2f2bd47c5f83d5ee15
2018-05-09 01:16:12 -07:00
Tim Yung 3e534b9aab RN: Switch `View` to `React.forwardRef`
Reviewed By: bvaughn, sophiebits

Differential Revision: D7896711

fbshipit-source-id: c10c8a14a00ac2d67605e6e4fe1a341b4688fdd8
2018-05-09 01:16:11 -07:00
Tim Yung 5d4c542c58 RN: Refactor `MockNativeMethods` in Jest
Reviewed By: sahrens

Differential Revision: D7917498

fbshipit-source-id: 97636080588bf2641a56256688cb0f2ec81ae463
2018-05-09 01:16:11 -07:00
Sebastian Markbage a8e3c7f578 Yolo Delete ReactNativePropRegistry
Summary:
Changed StyleSheet.create to be the identity function. We no longer hide it behind an opaque number. Better for types and perf since we don't use it.

I don't really know if we have/need any safer way of rolling this out than just landing it.

It can break if the object passed to StyleSheet.create is mutated afterwards but that isn't a practice anywhere I've seen.

Reviewed By: sophiebits

Differential Revision: D7530023

fbshipit-source-id: bc1afa879c5a5d9cd95cb13bc8ff3347b3622851
2018-04-09 18:46:11 -07:00
Matt Oakes 43014eaf19 Fix #18279: Add 'addNetworkingHandler' to jest mock setup
Summary:
Fixes #18279 by adding the correct methods to the jest mocks setup file.

Test by no longer including the workarounds in [issue comments](https://github.com/facebook/react-native/issues/18279#issuecomment-374177940). A [comment from hramos](https://github.com/facebook/react-native/issues/18279#issuecomment-371914037) mentioned improving the test coverage as well, but I wasn't certain how to achieve that.

[GENERAL] [BUGFIX] [BlobManager] - Fixed the jest mocks to avoid breaking tests
Closes https://github.com/facebook/react-native/pull/18718

Differential Revision: D7542458

Pulled By: hramos

fbshipit-source-id: 77c9c7cae77971d62e878c4832b2e1d205131e8f
2018-04-09 11:33:24 -07:00
Eli White 3e9a371ace Mock ReactNative.NativeComponent native methods in jest
Reviewed By: yungsters

Differential Revision: D7218964

fbshipit-source-id: f4b25a533b7e150c978863ff8411dc80937a4fed
2018-03-09 13:43:30 -08:00
Maxime Thirouin 59c7b2cfac Add missing mock for AppState (removeEventListener)
Summary:
I am testing with Jest a component that use [AppState.removeEventListener](https://facebook.github.io/react-native/docs/appstate.html#removeeventlistener) and I am currently facing a fatal error saying that `AppState.removeEventListener` is `undefined`.

Create a component that uses `AppState`, e.g.

```jsx
import React, { Component } from 'react';
import { AppState } from 'react-native';

class TestComponent extends Component {
  componentDidMount() {
    AppState.addEventListener('change', this.stateChangeListener);
  }
  componentWillUnmount() {
    AppState.removeEventListener('change', this.stateChangeListener);
  }
}
```

It should pass test using Jest (snapshots)

It's the continuation of #11199. This PR finish the mock for the native module `AppState`.

[ GENERAL  ]   [ BUGFIX      ]   [AppState] Add missing mock for Jest for `removeEventListener` method.
Closes https://github.com/facebook/react-native/pull/17908

Differential Revision: D7083144

Pulled By: shergin

fbshipit-source-id: eafa07f064f971c3d657f2ffc9c00766c0925bac
2018-02-25 22:18:30 -08:00
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00
uk-ar 11a2a35c63 Fix Jest mocks for Dimensions module
Summary:
Jest mock for Dimensions.get("screen") is missing. Tests fail with error message:

    Invariant Violation: No dimension set for key screen

Run test with usage of Dimensions.get("screen")

[GENERAL] [BUGFIX] [jest/setup.js] - Fix Jest mocks for Dimensions module
Closes https://github.com/facebook/react-native/pull/17017

Differential Revision: D6471719

Pulled By: TheSavior

fbshipit-source-id: de27b2819d088fefe20dfca94ab5672fdec5f0e1
2017-12-03 16:48:17 -08:00
Tim Wang 7fb3a9229d Fix Jest mocks for NetInfo module.
Summary:
Jest mock for `NetInfo.getConnectionInfo()` is missing. Tests are fail with error message:
```
TypeError: _reactNative.NetInfo.getConnectionInfo is not a function
```
And cleaned code in this files for unified code styles.

Run test with usage of `NetInfo.getConnectionInfo()`

[GENERAL] [BUGFIX] [jest/setup.js] - Fix Jest mocks for NetInfo module
Closes https://github.com/facebook/react-native/pull/16722

Differential Revision: D6298133

Pulled By: hramos

fbshipit-source-id: 589cf6fed93965e7a09823015f2793f5c68a9c3b
2017-11-10 10:12:30 -08:00
Maksym Rusynyk 3088096684 Return request id in jest mock for requestAnimationFrame
Summary:
`Jest` allows to use fake timers and according to https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame the return value should be `A long integer value, the request id, that uniquely identifies the entry in the callback list`. This allows to use `cancelAnimationFrame`.

In current implementation of `jest/setup.js`, the return value is undefined. Therefore it's not possible to cancel the animation frame request.

```
let id = null;
const registerCallback = (callback) => {
  clearCallback();
  id = requestAnimationFrame(() => {
    id = null;
    callback();
  });
};
const clearCallback = () => {
  if (null !== id) {
    cancelAnimationFrame(id);
    id = null;
  }
};
```

```
jest.useFakeTimers();

const callback = jest.fn();
registerCallback(callback);
clearCallback();

jest.runAllTimers();
expect(callback).toHaveBeenCalledTimes(0); // Will be error in current implementation, since nothing is cleared. And test will pass, after MR is merged
```

This is fake example, but the real usage is when the animation frame request should be removed on `ComponentWillUnmount`.

 [JEST] [BUGFIX] [requestAnimationFrame] - return request id
Closes https://github.com/facebook/react-native/pull/16367

Differential Revision: D6060578

Pulled By: ericnakagawa

fbshipit-source-id: c785a3380f5e267b48ae16fcf34dbbf95fa54178
2017-10-14 14:03:16 -07:00
Julien Moutte bbceb48dbb Direct assignment of the ref to avoid warning when mocking.
Summary:
When Jest is mocking native components that are assigned a ref with an arrow function, a warning is generated about stateless components which can not have a ref. This does not happen when the ref is assigned directly.

Fixes #16045.
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

The test provided in the related issue is used to validate the fix. I don't know how to detect console warnings in a Jest test.
Closes https://github.com/facebook/react-native/pull/16046

Differential Revision: D6017903

Pulled By: ericnakagawa

fbshipit-source-id: a7ed61c39f141a4094f08fc875289a7a79ebe9e8
2017-10-09 21:46:20 -07:00
Janic Duplessis 1af645b2fd Validate that JS and Native code versions match for RN releases
Summary:
Basic implementation of the proposal in #15271

Note that this should not affect facebook internally since they are not using OSS releases.

Points to consider:
- How strict should the version match be, right now I just match exact versions.
- Wasn't able to use haste for ReactNativeVersion because I was getting duplicate module provider caused by the template file in scripts/versiontemplates. I tried adding the scripts folder to modulePathIgnorePatterns in package.json but that didn't help.
- Redscreen vs. warning, I think warning is useless because if the app crashes you won't have time to see the warning.
- Should the check and native modules be __DEV__ only?

**Test plan**
Tested that it works when version match and that it redscreens when versions don't before getting other errors on Android and iOS.
Closes https://github.com/facebook/react-native/pull/15518

Differential Revision: D5813551

Pulled By: hramos

fbshipit-source-id: 901757e25724b0f22bf39de172b56309d0dd5a95
2017-09-27 18:31:15 -07:00
Tim Wang 165f876730 Add BlobModule native module mock to jest setup
Summary:
React Native v0.48.0 shipped `WebSocketModule` support with `BlobModule` as dependency. But `BlobModule` is not mocked in jest which will cause render tests failed.

Reference implantation: [BlobModule.java](ed903099b4/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobModule.java)

Related PR: #11417
Related issue: #15810

Passed CI tests.
Need render a component in jest with WebSocketModule as dependency.
Closes https://github.com/facebook/react-native/pull/15843

Differential Revision: D5783263

Pulled By: shergin

fbshipit-source-id: 2386692f4a644796da2fd66b3135da9f5911663e
2017-09-06 23:51:57 -07:00
Brian Vaughn 046f600cc2 React 16 beta 5 sync (5495e49...c3718c4)
Reviewed By: spicyj

Differential Revision: D5564030

fbshipit-source-id: fd3e6133df7ee8e7488a3c515ce6c783c11d9401
2017-08-09 12:35:30 -07:00
Alex Dvornikov 70edc2fd80 Upgrade metro-bundler to v0.10.0
Reviewed By: davidaurelio

Differential Revision: D5469746

fbshipit-source-id: 1d2c0f6c5bb9761cfc54b6c9fdbb1a9f20f535ea
2017-07-21 09:40:15 -07:00
Eli White aafccdf622 Revert D5409825: [RN] Convert easy files to Prettier
Differential Revision: D5409825

fbshipit-source-id: f797a40b58bc6bcc6ae53ed820a10ab49d3f10f5
2017-07-12 19:23:58 -07:00
Eli White c198911561 Convert easy files to Prettier
Reviewed By: zertosh

Differential Revision: D5409825

fbshipit-source-id: 81f67be174cc8ecfcd0955dfec83955ebdc84622
2017-07-12 16:08:22 -07:00
Hank Brekke 0797dae500 Jest Mocks for NetInfo and Linking
Summary:
This isn't exhaustive, but it's a few more functions that these modules normally export which need to be stubbed.
Closes https://github.com/facebook/react-native/pull/14432

Differential Revision: D5345928

Pulled By: shergin

fbshipit-source-id: f333056ac43ce7c75c6734bca8dc9035745721df
2017-06-29 01:00:39 -07:00
David Aurelio 1faf40b02a Upgrade metro-bundler to v0.9.0
Summary: Upgrade metro-bundler to v0.9.0. This version has no functional change. The only change is that the structure of the npm package reflects the structure of the source code.

Reviewed By: bestander

Differential Revision: D5315651

fbshipit-source-id: 3a69337106d4ccf708823c80d304941973360e8e
2017-06-24 17:15:55 -07:00
Christoph Pojer 236e9e4d01 Remove react-native/packager folder.
Summary: This folder is not necessary any longer. All the code now lives in https://github.com/facebook/metro-bundler

Reviewed By: davidaurelio, jeanlauliac

Differential Revision: D5199196

fbshipit-source-id: 35bf0f10a9163f53426db9a76f8f853dceb69167
2017-06-07 07:30:32 -07:00
Kyle Pinkham 7c2ef3281f Fixed ImageLoader Mock for Android
Summary:
When trying to mock an Image on Android, this error occurs referencing the ImageLoader mock in setup.js:
```
/Users/.../node_modules/react-native/jest/setup.js:120
return success(320,240);
       ^

TypeError: success is not a function
    at /Users/.../node_modules/react-native/jest/setup.js:120:8
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
```
- Mocking Images works for iOS but not Android.
- Since Image.android.js uses ImageLoader vs ImageViewManager, the code cannot be carried over from iOS.

Since this is code within the testing framework, the existing tests should test this. If there is no existing test coverage, then this would need to be done.
Closes https://github.com/facebook/react-native/pull/14262

Differential Revision: D5162640

Pulled By: shergin

fbshipit-source-id: 5b1efbbb685b767e09b5c7fb05f073445c94a3aa
2017-05-31 23:49:35 -07:00
Eli White dc339f77f3 Adding mocks for missing native modules
Reviewed By: fkgozali

Differential Revision: D5052517

fbshipit-source-id: 649e0f01c3d8534b898690f9140d5fc610676041
2017-05-15 15:45:26 -07:00
ZauberNerd 31a0b8788f Add jest mock for 'PushNotificationManager'
Summary:
`PushNotificationIOS` is a library that makes use of the
`PushNotificationManager` native module.
This commit adds a jest mock for its native module so that code that
uses `PushNotificationIOS` can be tested using jest.

In order to enable behaviour in unit tests it is possible to replace or
overwrite the mock implementation, see the [jest guide on
mocks](https://facebook.github.io/jest/docs/mock-functions.html).
By doing something similar to:
```javascript
import { NativeModules } from 'react-native';
const { PushNotificationManager } = NativeModules;
// mock 'checkPermissions' to return a different value than the default:
PushNotificationManager.checkPermissions.mockImplementationOnce((callback) => {
    // execute callback in next tick to enable async behaviour
    process.nextTick(() => callback({
        alert: false,
        badge: false,
        sound: false
    }));
});
// execute unit tests for code that makes use of 'PushNotificationIOS'
```
Closes https://github.com/facebook/react-native/pull/13410

Differential Revision: D5043904

Pulled By: cpojer

fbshipit-source-id: 11e73cd215ba6854d06f4ac7a5aea0ab4be26584
2017-05-11 03:50:52 -07:00
Emily Janzer 8ae4c3fcfd Add request/cancelAnimationFrame to jest setup
Reviewed By: cpojer

Differential Revision: D5005587

fbshipit-source-id: 653c281df9025a75ed8eecd22a2e64eaf188bf3e
2017-05-04 17:35:06 -07:00
Emmanouil Konstantinidis 5121434262 Mock Linking - openURL & canOpenURL
Summary:
This PR brings 2 basic mocks for `Linking`'s `openURL` & `canOpenURL` methods. Below you can find 2 examples on how to it works.

```javascript

  it('presses the open website button', () => {
    const wrapper = shallow(<Info />);

    expect(wrapper).toBeDefined();

    wrapper.find('TouchableOpacity').simulate('press');

    expect(Linking.openURL).toHaveBeenCalledTimes(1);
    expect(Linking.openURL).toHaveBeenCalledWith('https://www.hello.world/');
  });

  it('presses the call button', () => {
    const wrapper = shallow(<MoreInfo />);

    expect(wrapper).toBeDefined();

    wrapper.find('TouchableOpacity').simulate('press');

    expect(Linking.canOpenURL).toHaveBeenCalledTimes(1);
    expect(Linking.canOpenURL).toHaveBeenCalledWith('tel:01273123123');
  });
````
Closes https://github.com/facebook/react-native/pull/12839

Differential Revision: D4908903

Pulled By: javache

fbshipit-source-id: 0b62e9c2a7f920dc8bf0a49c1973f65c473eb653
2017-04-19 04:20:12 -07:00
William Durand 6a1e0516e9 Add Geolocation API Jest mock
Summary:
Hello!

The [Geolocation API](https://facebook.github.io/react-native/docs/geolocation.html) is currently not mocked in Jest, which often leads to an `Invariant Violation: Native module cannot be null` error. This patch adds a basic Jest configuration similar to the existing ones for the other modules.

None unfortunately, but this patch makes my test suite all green 😉

Thanks,
William
Closes https://github.com/facebook/react-native/pull/13442

Differential Revision: D4883830

Pulled By: javache

fbshipit-source-id: c2a976834cca7537bd832a698e8cd25cf877705b
2017-04-13 09:35:22 -07:00
ZauberNerd 469acbaa9d fix mock for AsyncLocalStorage
Summary:
The current mock of `AsyncLocalStorage` seems to mock parts of the
`AsyncStorage` API that can't be found on the `AsyncLocalStorage`
object itself and therefore it doesn't work as expected.

What it should do is mock the API of `AsyncLocalStorage` which is a
`NativeModule` so that the `AsyncStorage` module can be used in tests
and it will require the mocked methods.

In order to enable behaviour in unit tests it is possible to replace or
overwrite the mock implementation, see the [jest guide on mocks](https://facebook.github.io/jest/docs/mock-functions.html).
By doing something similar to:
```javascript
import { NativeModules } from 'react-native';
const { AsyncLocalStorage } = NativeModules;
// mock 'multiGet', in order to allow 'AsyncStorage.getItem('myKey')'
AsyncLocalStorage.multiGet.mockImplementationOnce((keys, callback) => {
    callback(null, [['myKey', 'myValue']]);
});
// execute unit tests for code that makes use of 'AsyncStorage'
```
Closes https://github.com/facebook/react-native/pull/13433

Differential Revision: D4883389

Pulled By: javache

fbshipit-source-id: 92a0ee94480b3022acc748e306ee2d4ee7a9869d
2017-04-13 06:32:47 -07:00
Brian Vaughn 703936d9e3 Sync React master (and 16 alpha 4)
Reviewed By: sebmarkbage

Differential Revision: D4747529

fbshipit-source-id: 5efea6422a2502f27c1b23506cbae2187c7f7b0d
2017-03-22 21:30:50 -07:00
Ashwin Bharambe 95c1926193 Introduce `DeviceInfo` as a new native module
Summary:
The `UIManager` already has a lot of responsibilities and is deeply
tied with React Native's view architecture. This diff separates out a
`DeviceInfo` native module to provide information about screen dimensions and
font scale, etc.

Reviewed By: fkgozali

Differential Revision: D4713834

fbshipit-source-id: f2ee93acf876a4221c29a8c731f5abeffbb97974
2017-03-17 17:01:57 -07:00
Sebastian Markbage c3b25c9059 Patch up for future React Sync
Reviewed By: spicyj, bvaughn

Differential Revision: D4523259

fbshipit-source-id: 317a26ce3e9e48553a7f7c856dd6b48038b4b2ea
2017-02-08 14:50:43 -08:00
Christoph Pojer a2c84d14ce Remove `react-packager` indirection.
Summary:
This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense.

Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change?

Reviewed By: jeanlauliac

Differential Revision: D4487867

fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb
2017-02-02 05:44:15 -08:00
Alex Kotliarskyi 2275ca5a7f Add UIManager method mocks to jest/setup.js
Reviewed By: cpojer

Differential Revision: D4420536

fbshipit-source-id: 4fb5c1857974b4d32e21de6d5b5b581213aad87b
2017-01-20 16:43:42 -08:00
Mike Grabowski 8305743725 Fix jest tests
Summary: https://www.facebook.com/groups/reactnativeoss/permalink/1627334037563224/

Differential Revision: D4357483

fbshipit-source-id: 32e9d91c2348e4046a5cfaa08eab34d1f4dd2f7e
2016-12-21 07:58:25 -08:00
Emmanouil Konstantinidis 797506f09f Jest - Support Immutable Objects for ListViewDataSource mock
Summary:
Currently the jest mock for `ListViewDataSource` has a property called `items` which returns the number of items of the data source. Example from a snapshot:

    ListViewDataSource {
      "items": 6,
    }

If the datablob includes immutable Maps like:

    const dataBlob = {
      'alpha': immutable.Map({ name: 'Alpha' }),
      'beta': immutable.Map({ name: 'Beta' }),
    };

then the result is:

    ListViewDataSource {
      "items": NaN,
    }

This PR checks if the properties of the `dataBlob` are immutable Maps and then checks whether they are empty.

The result for the above dataBlob would be:

    ListViewDataSource {
      "items": 2,
    }
Closes https://github.com/facebook/react-native/pull/11567

Differential Revision: D4354977

Pulled By: cpojer

fbshipit-source-id: 9f6bd6ea9896eebd9373344a43ffe97deee5015b
2016-12-20 16:58:29 -08:00