mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Add some native module method test cases
Summary: Just a little more rigorous Reviewed By: shergin Differential Revision: D14790912 fbshipit-source-id: 0a4c9b6ea68466efb060c9c90572ff8987fdbd26
This commit is contained in:
committed by
Facebook Github Bot
parent
3155ddf2e8
commit
f04c039a98
@@ -57,6 +57,9 @@ static RCTModuleMethod *buildSyncMethodWithMethodSignature(const char *methodSig
|
|||||||
|
|
||||||
- (id)echoString:(NSString *)input { return input; }
|
- (id)echoString:(NSString *)input { return input; }
|
||||||
- (id)methodThatReturnsNil { return nil; }
|
- (id)methodThatReturnsNil { return nil; }
|
||||||
|
- (void)openURL:(NSURL *)URL resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {}
|
||||||
|
- (void)openURL:(NSURL *)URL callback:(RCTResponseSenderBlock)callback {}
|
||||||
|
- (id)methodThatCallsCallbackWithArg:(NSString *)input callback:(RCTResponseSenderBlock)callback { callback(@[input]); return nil; }
|
||||||
|
|
||||||
- (void)testNonnull
|
- (void)testNonnull
|
||||||
{
|
{
|
||||||
@@ -147,18 +150,50 @@ static RCTModuleMethod *buildSyncMethodWithMethodSignature(const char *methodSig
|
|||||||
const char *methodSignature = "doFoo";
|
const char *methodSignature = "doFoo";
|
||||||
RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature);
|
RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature);
|
||||||
XCTAssertTrue(method.functionType == RCTFunctionTypeNormal);
|
XCTAssertTrue(method.functionType == RCTFunctionTypeNormal);
|
||||||
|
XCTAssertFalse(RCTLogsError(^{
|
||||||
|
// Invoke method to trigger parsing
|
||||||
|
__unused SEL selector = method.selector;
|
||||||
|
}), @"Unexpected error when parsing normal function");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char *methodSignature = "openURL:(NSURL *)URL callback:(RCTResponseSenderBlock)callBack";
|
||||||
|
RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature);
|
||||||
|
XCTAssertTrue(method.functionType == RCTFunctionTypeNormal);
|
||||||
|
XCTAssertFalse(RCTLogsError(^{
|
||||||
|
// Invoke method to trigger parsing
|
||||||
|
__unused SEL selector = method.selector;
|
||||||
|
}), @"Unexpected error when parsing normal function with callback");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char *methodSignature = "openURL:(NSURL *)URL resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject";
|
const char *methodSignature = "openURL:(NSURL *)URL resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject";
|
||||||
RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature);
|
RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature);
|
||||||
XCTAssertTrue(method.functionType == RCTFunctionTypePromise);
|
XCTAssertTrue(method.functionType == RCTFunctionTypePromise);
|
||||||
|
XCTAssertFalse(RCTLogsError(^{
|
||||||
|
// Invoke method to trigger parsing
|
||||||
|
__unused SEL selector = method.selector;
|
||||||
|
}), @"Unexpected error when parsing promise function");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char *methodSignature = "echoString:(NSString *)input";
|
const char *methodSignature = "echoString:(NSString *)input";
|
||||||
RCTModuleMethod *method = buildSyncMethodWithMethodSignature(methodSignature);
|
RCTModuleMethod *method = buildSyncMethodWithMethodSignature(methodSignature);
|
||||||
XCTAssertTrue(method.functionType == RCTFunctionTypeSync);
|
XCTAssertTrue(method.functionType == RCTFunctionTypeSync);
|
||||||
|
XCTAssertFalse(RCTLogsError(^{
|
||||||
|
// Invoke method to trigger parsing
|
||||||
|
__unused SEL selector = method.selector;
|
||||||
|
}), @"Unexpected error when parsing sync function");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char *methodSignature = "methodThatCallsCallbackWithArg:(NSString *)input callback:(RCTResponseSenderBlock)callback";
|
||||||
|
RCTModuleMethod *method = buildSyncMethodWithMethodSignature(methodSignature);
|
||||||
|
XCTAssertTrue(method.functionType == RCTFunctionTypeSync);
|
||||||
|
XCTAssertFalse(RCTLogsError(^{
|
||||||
|
// Invoke method to trigger parsing
|
||||||
|
__unused SEL selector = method.selector;
|
||||||
|
}), @"Unexpected error when parsing sync function with callback");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user