Include actual type of `Profiler#id` on type mismatch (#20306)

This commit is contained in:
Sebastian Silbermann 2021-04-08 19:36:42 +02:00 committed by GitHub
parent 1214b302e1
commit 75c616554d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -651,7 +651,10 @@ function createFiberFromProfiler(
): Fiber {
if (__DEV__) {
if (typeof pendingProps.id !== 'string') {
console.error('Profiler must specify an "id" as a prop');
console.error(
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
typeof pendingProps.id,
);
}
}

View File

@ -651,7 +651,10 @@ function createFiberFromProfiler(
): Fiber {
if (__DEV__) {
if (typeof pendingProps.id !== 'string') {
console.error('Profiler must specify an "id" as a prop');
console.error(
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
typeof pendingProps.id,
);
}
}

View File

@ -136,9 +136,12 @@ describe('Profiler', () => {
it('should warn if required params are missing', () => {
expect(() => {
ReactTestRenderer.create(<React.Profiler />);
}).toErrorDev('Profiler must specify an "id" as a prop', {
withoutStack: true,
});
}).toErrorDev(
'Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.',
{
withoutStack: true,
},
);
});
}