react/scripts/babel/__tests__/transform-lazy-jsx-import-test.js
Sebastian Markbåge fc74a3a3e6
Transform JSX to Lazy Requires instead of Wrappers (#30433)
This ensures that we can keep overriding what runtime to use by
resetting modules while still using the automatic JSX plugin. This is
like the "inline requires" transform but just for JSX.

I got sick of trying to figure out workarounds to hide the extra stack
frame that appears due to the wrappers.
2024-07-23 15:51:23 -04:00

31 lines
821 B
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.
*/
'use strict';
describe('transform-lazy-jsx-import', () => {
it('should use the mocked version of the "react" runtime in jsx', () => {
jest.resetModules();
const mock = jest.fn(type => 'fakejsx: ' + type);
if (__DEV__) {
jest.mock('react/jsx-dev-runtime', () => {
return {
jsxDEV: mock,
};
});
} else {
jest.mock('react/jsx-runtime', () => ({
jsx: mock,
jsxs: mock,
}));
}
// eslint-disable-next-line react/react-in-jsx-scope
const x = <div />;
expect(x).toBe('fakejsx: div');
expect(mock).toHaveBeenCalledTimes(1);
});
});