Skip to content

Commit

Permalink
[React Native] Improve logging for missing view configs and invalid v…
Browse files Browse the repository at this point in the history
…iew config getter functions
  • Loading branch information
JoshuaGross committed Sep 25, 2019
1 parent 9942896 commit 9eea5d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string {
);
invariant(
typeof callback === 'function',
'View config getter callback must be a function: %s (received %s)',
'View config getter callback for component `%s` must be a function (received `%s`)',
name,
callback === null ? 'null' : typeof callback,
);
Expand All @@ -100,7 +100,7 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> {
if (typeof callback !== 'function') {
invariant(
false,
'View config registration not found for name %s (received %s).%s',
'View config getter callback for component `%s` must be a function (received `%s`).%s',
name,
callback === null ? 'null' : typeof callback,
typeof name[0] === 'string' && /[a-z]/.test(name[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ describe('ReactNativeError', () => {
});

it('should throw error if null component registration getter is used', () => {
let error;
try {
createReactNativeComponentClass('View', null);
} catch (e) {
error = e;
}

expect(error.toString()).toBe('Invariant Violation: View config getter callback must be a function: View (received null)');
expect(() => {
try {
createReactNativeComponentClass('View', null);
} catch (e) {
throw new Error(e.toString());
}
}).toThrow(
'Invariant Violation: View config getter callback for component `View` must be a function (received `null`)',
);
});

it('should be able to extract a component stack from a native view', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string {
);
invariant(
typeof callback === 'function',
'View config getter callback must be a function: %s (received %s)',
'View config getter callback for component `%s` must be a function (received `%s`)',
name,
callback === null ? 'null' : typeof callback,
);
Expand All @@ -97,7 +97,7 @@ exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> {
if (typeof callback !== 'function') {
invariant(
false,
'View config registration not found for name %s (received %s).%s',
'View config getter callback for component `%s` must be a function (received `%s`).%s',
name,
callback === null ? 'null' : typeof callback,
typeof name[0] === 'string' && /[a-z]/.test(name[0])
Expand Down

0 comments on commit 9eea5d5

Please sign in to comment.