Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show warning when overwrite existing preprocessor #34479

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Libraries/StyleSheet/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@ module.exports = {
return;
}

if (__DEV__ && typeof value.process === 'function') {
if (
__DEV__ &&
typeof value.process === 'function' &&
typeof ReactNativeStyleAttributes[property]?.process === 'function' &&
value.process !== ReactNativeStyleAttributes[property]?.process
) {
console.warn(`Overwriting ${property} style attribute preprocessor`);
}

Expand Down
48 changes: 48 additions & 0 deletions Libraries/StyleSheet/__tests__/StyleSheet-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.
*
* @emails oncall+react_native
* @format
*/

import {setStyleAttributePreprocessor} from '../StyleSheet';

describe(setStyleAttributePreprocessor, () => {
const originalConsoleWarn = console.warn;

beforeEach(() => {
jest.resetModules();
console.warn = jest.fn();
});

afterEach(() => {
console.warn = originalConsoleWarn;
});

it('should not show warning when set preprocessor first time', () => {
const spyConsole = jest.spyOn(global.console, 'warn');
setStyleAttributePreprocessor(
'fontFamily',
(fontFamily: string) => fontFamily,
);
expect(spyConsole).not.toHaveBeenCalled();
});

it('should show warning when overwrite the preprocessor', () => {
const spyConsole = jest.spyOn(global.console, 'warn');
setStyleAttributePreprocessor(
'fontFamily',
(fontFamily: string) => fontFamily,
);
setStyleAttributePreprocessor(
'fontFamily',
(fontFamily: string) => `Scoped-${fontFamily}`,
);
expect(spyConsole).toHaveBeenCalledWith(
'Overwriting fontFamily style attribute preprocessor',
);
});
});