mirror of
https://github.com/apache/superset.git
synced 2026-05-29 20:29:34 +00:00
fix(react18): address review feedback on logging test + AvatarGroup
- logging.test: replace require() with jest.isolateModules() + jest.requireActual() so the file passes @typescript-eslint/no-require-imports. - AvatarGroup: re-introduce forwardRef parity with Avatar by wrapping AntdAvatar.Group (plain FC) in a span the ref attaches to, so it can be used as a Tooltip / Popover anchor without findDOMNode fallback.
This commit is contained in:
@@ -16,13 +16,24 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
type LoggingModule = typeof import('./index');
|
||||
|
||||
const loadLogging = (): LoggingModule['logging'] => {
|
||||
let logging: LoggingModule['logging'] | undefined;
|
||||
jest.isolateModules(() => {
|
||||
({ logging } = jest.requireActual<LoggingModule>(
|
||||
'@apache-superset/core/utils',
|
||||
));
|
||||
});
|
||||
return logging!;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
test('should pipe to `console` methods', () => {
|
||||
const { logging } = require('@apache-superset/core/utils');
|
||||
const logging = loadLogging();
|
||||
|
||||
jest.spyOn(logging, 'debug').mockImplementation();
|
||||
jest.spyOn(logging, 'log').mockImplementation();
|
||||
@@ -53,7 +64,7 @@ test('should use noop functions when console unavailable', () => {
|
||||
const originalConsole = window.console;
|
||||
Object.assign(window, { console: undefined });
|
||||
try {
|
||||
const { logging } = require('@apache-superset/core/utils');
|
||||
const logging = loadLogging();
|
||||
|
||||
expect(() => {
|
||||
logging.debug();
|
||||
|
||||
@@ -25,8 +25,15 @@ export const Avatar = forwardRef<HTMLSpanElement, AvatarProps>((props, ref) => (
|
||||
<AntdAvatar ref={ref} {...props} />
|
||||
));
|
||||
|
||||
export const AvatarGroup = (props: AvatarGroupProps) => (
|
||||
<AntdAvatar.Group {...props} />
|
||||
// antd Avatar.Group is a plain function component without forwardRef; wrap in
|
||||
// a span so this component can be a Tooltip / Popover trigger and skip the
|
||||
// findDOMNode fallback.
|
||||
export const AvatarGroup = forwardRef<HTMLSpanElement, AvatarGroupProps>(
|
||||
(props, ref) => (
|
||||
<span ref={ref}>
|
||||
<AntdAvatar.Group {...props} />
|
||||
</span>
|
||||
),
|
||||
);
|
||||
|
||||
export type { AvatarProps, AvatarGroupProps };
|
||||
|
||||
Reference in New Issue
Block a user