mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add test for sync methods (type=sync)
Summary: Adds a test for synchronous methods (`type === 'sync'`) in NativeModules. This doesn't modify any behaviour. Reviewed By: amnn Differential Revision: D15804757 fbshipit-source-id: 4db76dbd0b0b111ed9311d4b7ec35a077c377f01
This commit is contained in:
committed by
Facebook Github Bot
parent
88e9098a64
commit
37bbfa663d
@@ -18,16 +18,16 @@ const remoteModulesConfig: $ReadOnlyArray<ModuleConfig> = [
|
||||
[
|
||||
'RemoteModule1',
|
||||
null,
|
||||
['remoteMethod', 'promiseMethod', 'promiseReturningMethod'],
|
||||
['remoteMethod', 'promiseMethod', 'promiseReturningMethod', 'syncMethod'],
|
||||
[2 /* promiseReturningMethod */],
|
||||
null,
|
||||
[3 /* syncMethod */],
|
||||
],
|
||||
[
|
||||
'RemoteModule2',
|
||||
null,
|
||||
['remoteMethod', 'promiseMethod', 'promiseReturningMethod'],
|
||||
['remoteMethod', 'promiseMethod', 'promiseReturningMethod', 'syncMethod'],
|
||||
[2 /* promiseReturningMethod */],
|
||||
null,
|
||||
[3 /* syncMethod */],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -181,6 +181,53 @@ describe('MessageQueue', function() {
|
||||
}).toThrow();
|
||||
await promise2;
|
||||
});
|
||||
|
||||
describe('sync methods', () => {
|
||||
afterEach(function() {
|
||||
delete global.nativeCallSyncHook;
|
||||
});
|
||||
|
||||
it('throwing an exception', function() {
|
||||
global.nativeCallSyncHook = jest.fn(() => {
|
||||
throw new Error('firstFailure');
|
||||
});
|
||||
|
||||
let error;
|
||||
try {
|
||||
NativeModules.RemoteModule1.syncMethod('paloAlto', 'menloPark');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(global.nativeCallSyncHook).toBeCalledTimes(1);
|
||||
expect(global.nativeCallSyncHook).toBeCalledWith(
|
||||
0, // `RemoteModule1`
|
||||
3, // `syncMethod`
|
||||
['paloAlto', 'menloPark'],
|
||||
);
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(error).toMatchObject({
|
||||
message: 'firstFailure',
|
||||
});
|
||||
});
|
||||
|
||||
it('returning a value', function() {
|
||||
global.nativeCallSyncHook = jest.fn(() => {
|
||||
return 'secondSucc';
|
||||
});
|
||||
|
||||
const result = NativeModules.RemoteModule2.syncMethod('mac', 'windows');
|
||||
|
||||
expect(global.nativeCallSyncHook).toBeCalledTimes(1);
|
||||
expect(global.nativeCallSyncHook).toBeCalledWith(
|
||||
1, // `RemoteModule2`
|
||||
3, // `syncMethod`
|
||||
['mac', 'windows'],
|
||||
);
|
||||
|
||||
expect(result).toBe('secondSucc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const linesByFile = new Map();
|
||||
|
||||
Reference in New Issue
Block a user