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

test(jest): fail tests when encountering console messages #24368

Closed
wants to merge 6 commits into from
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
Binary file modified frontend/__snapshots__/scenes-app-dashboards--edit--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export const PropertyFilterButton = React.forwardRef<HTMLElement, PropertyFilter
)

if (disabledReason) {
return <Tooltip title={disabledReason}>{button}</Tooltip>
return (
<Tooltip title={disabledReason} ref={ref}>
{button}
</Tooltip>
)
}

return button
Expand Down
29 changes: 16 additions & 13 deletions frontend/src/lib/lemon-ui/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ export interface TooltipProps {
visible?: boolean
}

export function Tooltip({
children,
title,
className = '',
placement = 'top',
offset = 8,
arrowOffset,
delayMs = 500,
closeDelayMs = 0, // Set this to some delay to ensure the content stays open when hovered
visible: controlledOpen,
}: TooltipProps): JSX.Element {
export const Tooltip = React.forwardRef<HTMLElement, TooltipProps>(function Tooltip(
{
children,
title,
className = '',
placement = 'top',
offset = 8,
arrowOffset,
delayMs = 500,
closeDelayMs = 0, // Set this to some delay to ensure the content stays open when hovered
visible: controlledOpen,
}: TooltipProps,
ref
): JSX.Element {
const [uncontrolledOpen, setUncontrolledOpen] = useState(false)
const caretRef = useRef(null)
const floatingContainer = useFloatingContainer()
Expand Down Expand Up @@ -94,7 +97,7 @@ export function Tooltip({
})

const childrenRef = (children as any).ref
const triggerRef = useMergeRefs([refs.setReference, childrenRef])
const triggerRef = useMergeRefs([refs.setReference, childrenRef, ref])

const child = React.isValidElement(children) ? children : <span>{children}</span>

Expand Down Expand Up @@ -143,4 +146,4 @@ export function Tooltip({
) : (
children
)
}
})
42 changes: 26 additions & 16 deletions frontend/src/lib/lemon-ui/icons/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './icons.scss'
import clsx from 'clsx'
import { LemonBadge, LemonBadgeProps } from 'lib/lemon-ui/LemonBadge'
import { CSSProperties, PropsWithChildren, SVGAttributes } from 'react'
import React from 'react'

interface IconWithBadgeProps {
content: LemonBadgeProps['content']
Expand Down Expand Up @@ -54,19 +55,25 @@ export interface LemonIconProps {
className?: string
}

const LemonIconBase: React.FC<SVGAttributes<SVGSVGElement>> = ({ className, ...props }) => (
<svg
className={clsx('LemonIcon', className)}
width="1em"
height="1em"
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
focusable="false"
aria-hidden="true"
{...props}
/>
)
const LemonIconBase = React.forwardRef<SVGSVGElement, SVGAttributes<SVGSVGElement>>(function LemonIconBase(
{ className, ...props },
ref
) {
return (
<svg
ref={ref}
className={clsx('LemonIcon', className)}
width="1em"
height="1em"
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
focusable="false"
aria-hidden="true"
{...props}
/>
)
})

// material design format-size icon
export function IconTextSize(props: LemonIconProps): JSX.Element {
Expand Down Expand Up @@ -500,16 +507,19 @@ export function Icon123(props: LemonIconProps): JSX.Element {
}

/** Material Design Groups icon. */
export function IconCohort(props: LemonIconProps): JSX.Element {
export const IconCohort = React.forwardRef<SVGSVGElement, LemonIconProps>(function IconCohort(
props: LemonIconProps,
ref
): JSX.Element {
return (
<LemonIconBase {...props}>
<LemonIconBase {...props} ref={ref}>
<path
d="m4 13c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm1.13 1.1c-.37-.06-.74-.1-1.13-.1-.99 0-1.93.21-2.78.58-.74.32-1.22 1.04-1.22 1.85v1.57h4.5v-1.61c0-.83.23-1.61.63-2.29zm14.87-1.1c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4 3.43c0-.81-.48-1.53-1.22-1.85-.85-.37-1.79-.58-2.78-.58-.39 0-.76.04-1.13.1.4.68.63 1.46.63 2.29v1.61h4.5zm-7.76-2.78c-1.17-.52-2.61-.9-4.24-.9s-3.07.39-4.24.9c-1.08.48-1.76 1.56-1.76 2.74v1.61h12v-1.61c0-1.18-.68-2.26-1.76-2.74zm-8.17 2.35c.09-.23.13-.39.91-.69.97-.38 1.99-.56 3.02-.56s2.05.18 3.02.56c.77.3.81.46.91.69zm3.93-8c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm0-2c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
fill="currentColor"
/>
</LemonIconBase>
)
}
})

/** Material Design Handyman icon. */
export function IconTools(props: LemonIconProps): JSX.Element {
Expand Down
4 changes: 3 additions & 1 deletion jest.setupAfterEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as React from 'react'
// whatever else you need in here
import failOnConsole from 'jest-fail-on-console'

global.React = React

failOnConsole()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"heatmap.js": "^2.0.5",
"husky": "^7.0.4",
"image-blob-reduce": "^4.1.0",
"jest-fail-on-console": "^3.3.0",
"kea": "^3.1.5",
"kea-forms": "^3.2.0",
"kea-loaders": "^3.0.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading