469acbaa9d
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 |
||
---|---|---|
.. | ||
mockComponent.js | ||
preprocessor.js | ||
setup.js |