mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Summary: from the original design of `StyleSheet.setStyleAttributePreprocessor()` in https://github.com/facebook/react-native/issues/11138, the overwriting warning shows when the existing preprocess is be overwritten. the behavior changes from https://github.com/facebook/react-native/commit/33b385825c72. This PR revises the logic back to original design. ## Changelog [Internal] [Fixed] - Show warning only when overwriting existing preprocessor in `StyleSheet.setStyleAttributePreprocessor()` Pull Request resolved: https://github.com/facebook/react-native/pull/34479 Test Plan: Unit Test ``` PASS Libraries/StyleSheet/__tests__/StyleSheet-test.js setStyleAttributePreprocessor ✓ should not show warning when set preprocessor first time (2 ms) ✓ should show warning when overwrite the preprocessor (1 ms) ``` Reviewed By: dmitryrykun Differential Revision: D38940676 Pulled By: cipolleschi fbshipit-source-id: 80cf30fff62f4a02c17f7f42b3260a6011d5fc82
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/**
|
|
* 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',
|
|
);
|
|
});
|
|
});
|