mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35106 This Diff remove the assert on the initializer in the EventEmitter in place of a more idiomatic check when the method is invoked. It aims to solve an internal error and promotes best practices for the iOS platform. ## Changelog: [iOS][Changed] Refactor RCTEventEmitter initialization Reviewed By: sammy-SC Differential Revision: D40762253 fbshipit-source-id: 83d26616ce147914948e536e9e4b1010758fb690
73 lines
1.5 KiB
Objective-C
73 lines
1.5 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <React/RCTEventEmitter.h>
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#pragma mark - Faulty EventEmitter
|
|
|
|
@interface RCTFaultyEventEmitter : RCTEventEmitter
|
|
@end
|
|
|
|
@implementation RCTFaultyEventEmitter {
|
|
NSString *_capturedMessage;
|
|
}
|
|
|
|
- (NSString *)capturedMessage
|
|
{
|
|
return _capturedMessage;
|
|
}
|
|
|
|
- (void)_log:(NSString *)message
|
|
{
|
|
_capturedMessage = message;
|
|
}
|
|
@end
|
|
|
|
#pragma mark - Proper EventEmitter
|
|
|
|
@interface RCTProperEventEmitter : RCTEventEmitter
|
|
@end
|
|
|
|
@implementation RCTProperEventEmitter
|
|
|
|
- (NSArray<NSString *> *)supportedEvents
|
|
{
|
|
return @[ @"myEvent" ];
|
|
}
|
|
@end
|
|
|
|
#pragma mark - Tests Code
|
|
|
|
@interface RCTEventEmitterTests : XCTestCase
|
|
|
|
@end
|
|
|
|
@implementation RCTEventEmitterTests
|
|
|
|
- (void)testEventEmitterSubclass_whenFaultySubclassInvokesSupportedEvents_raiseException
|
|
{
|
|
RCTEventEmitter *emitter = [[RCTFaultyEventEmitter alloc] init];
|
|
|
|
NSArray<NSString *> *events = emitter.supportedEvents;
|
|
XCTAssertNil(events);
|
|
XCTAssertEqualObjects(
|
|
((RCTFaultyEventEmitter *)emitter).capturedMessage,
|
|
@"RCTFaultyEventEmitter must implement the supportedEvents method");
|
|
}
|
|
|
|
- (void)testEventEmitterSubclass_whenProperSubclassInvokesSupportedEvents_itreturnsTheEvents
|
|
{
|
|
RCTEventEmitter *emitter = [[RCTProperEventEmitter alloc] init];
|
|
|
|
NSArray<NSString *> *events = emitter.supportedEvents;
|
|
|
|
XCTAssertEqualObjects(events, @[ @"myEvent" ]);
|
|
}
|
|
|
|
@end
|