From f04c039a983a4d4ad2b322674dbfdc19ef236a87 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Mon, 8 Apr 2019 09:10:44 -0700 Subject: [PATCH] Add some native module method test cases Summary: Just a little more rigorous Reviewed By: shergin Differential Revision: D14790912 fbshipit-source-id: 0a4c9b6ea68466efb060c9c90572ff8987fdbd26 --- .../RNTesterUnitTests/RCTModuleMethodTests.mm | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/RNTester/RNTesterUnitTests/RCTModuleMethodTests.mm b/RNTester/RNTesterUnitTests/RCTModuleMethodTests.mm index 3efc69053..c319d2649 100644 --- a/RNTester/RNTesterUnitTests/RCTModuleMethodTests.mm +++ b/RNTester/RNTesterUnitTests/RCTModuleMethodTests.mm @@ -57,6 +57,9 @@ static RCTModuleMethod *buildSyncMethodWithMethodSignature(const char *methodSig - (id)echoString:(NSString *)input { return input; } - (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 { @@ -147,18 +150,50 @@ static RCTModuleMethod *buildSyncMethodWithMethodSignature(const char *methodSig const char *methodSignature = "doFoo"; 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"); + } + + { + 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"; RCTModuleMethod *method = buildDefaultMethodWithMethodSignature(methodSignature); 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"; 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"); + } + + { + 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"); } }